BasicCAD - draw parallel lines in an area defined by the user

Started by prl, December 13, 2006, 05:44:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prl

This code draws parallel lines inside a boundary area defined by snapping points.  It was developed for a special purpose. You can do similar things using the hatch command.  It may be interesting to someone as a starting point for other things.

apl.d3m (the below code)

'APL.d3m (Aqua parallel lines routine)

'11 Dec 2006
'Tested and working with v15.3, 16.3 and 17.x

dim x(200), y(200), z(200)

offset = 50000

input "Enter distance between parallel lines: example 1.5", spacing$
sp = val(spacing$)

setpoint "Set 2 points for direction of lines for the new area", 2

pointval x1, y1, z1, 1
pointval x2, y2, z2, 2
sys(1)=0

dy = abs(y2 - y1)
dx = abs(x2 - x1)

rot = angle(dx,dy)

if (y2 - y1) < 0 and (x2 - x1) >= 0 then rot = -rot
if (y2 - y1) > 0 and (x2 - x1) <= 0 then rot = -rot


sys(41)=1 'rubberband line
setpoint "Set points to define the area boundary", 200
sys(41)=0

sys(36) = 1
npts = sys(1)

for i = 1 to npts
  pointval x(i), y(i), z(i), i
next i
sys(1) = 0

mark = sys(9) 'record current entity count
sys(242)=1 'Select object when created on
>plane
{
  for i = 1 to npts
    <pointxyz [x(i)+offset, y(i), 0]
  next i
}

>sethandle
{
<pointxyz [x1+offset, y1, 0]
}

>rotate
{
  <angle [-rot]
  <ThroughHandle 1
}

xmin = sys(196)
ymin = sys(197)
xmax = sys(198)
ymax = sys(199)


>line
{
<pointxyz [xmin, y1, 0]
<pointxyz [xmax, y1, 0]
}

'create lines above
n = 1
do while y1+n*sp < ymax 
  >line
  {
  <pointxyz [xmin, y1+n*sp, 0]
  <pointxyz [xmax, y1+n*sp, 0]
  }
n=n+1
loop

'create lines below
n = 1
do while y1-n*sp > ymin 
  >line
  {
  <pointxyz [xmin, y1-n*sp, 0]
  <pointxyz [xmax, y1-n*sp, 0]
  }
n=n+1
loop

'select all the new entities
sys(80)=0
sp1=mark+1
for j = sp1 to sys(9) 
  getattr j, type
  putattr j, type, 1
next j

>sethandle
{
<pointxyz [x1+offset, y1, 0]
}

>rotate
{
  <angle [rot]
  <ThroughHandle 1
}

sys(80)=0
'use sectioncutbyline to get the lines we want and store them to the clipboard
>SectionCutByLine
{
  <SelectOnly 0 'cut everything
  <Type 2 'keep both
  <SelectAfter 0 'select inside
  <Pointxyz [x(3)+offset, y(3), z(3)]
}

>sethandle
{
<pointxyz [x1+offset, y1, 0]
}

>copy
{
}

'reselect all the new entities again, this time to erase them
sys(80)=0
sp1=mark+1
for j = sp1 to sys(9) 
  getattr j, type
  putattr j, type, 1
next j

>erase
{
}

'insert the trimmed lines from the clipboard to the original position
>paste
{
<pointxyz [x1, y1, 0]
}

sys(80)=0

end



dmeek

Thanks. This is a good example to study, and learn more about BasicCAD.

support

prl between you and DT there are plenty of Basic CAD code examples for people who like to use those aspects of DesignCAD.

I just wanted to say thank you for all you do. Rarely in this day and age do we find people so willing to give so freely of their time, ideas, and efforts.

prl

Here is a theme and variation version of the original.  It uses the hatch command to generate the lines.  Interesting sections are the calibrated hatch scale to user spacing requirement, and also the code for positioning the seed point of the hatch.  I originally posted this yesterday but then upon trying the code it failed.  I tried to find the error but didn't and strangely enough later it worked fine.  Who knows????  If it fails for you, be kind and post the sample shape and two point lines you are trying to generate.

cheers

pplh.d3m (the below code)

'PPLH.d3m (Positioned parallel lines hatching routine)

'14 Dec 2006

dim x(200), y(200), z(200)

offset = 50000

input "Enter distance between parallel lines: example 1.5", spacing$
sp = val(spacing$)
hs = .8*sys(32)/8*sp 'hatch scale calibration

setpoint "Set 2 points for direction of lines for the new area", 2

pointval x1, y1, z1, 1
pointval x2, y2, z2, 2
sys(1)=0

dy = abs(y2 - y1)
dx = abs(x2 - x1)

rot = angle(dx,dy)

if (y2 - y1) < 0 and (x2 - x1) >= 0 then rot = -rot
if (y2 - y1) > 0 and (x2 - x1) <= 0 then rot = -rot

sys(41)=1 'rubberband line
setpoint "Set points to define the area boundary", 200
sys(41)=0

sys(36) = 1
npts = sys(1)

for i = 1 to npts
  pointval x(i), y(i), z(i), i
next i
sys(1) = 0

sys(242)=1 'Select object when created - on
>hatch
{
  <Name "LINES"
  <Scale [hs]
  <Angle [rot]
  for i = 1 to npts
    <pointxyz [x(i)+offset, y(i), 0]
  next i
}

sys(242)=0 'Select object when created - off for me normally

'reposition hatch seed point, do this by snapping to
'the middle edge of the hatch somewhere - looking for an origin point on the hatch
sys(1111)=1 'first turn on snap mode within hatches
xh=(x(2)-x(1))/2.0+x(1)
yh=(y(2)-y(1))/2.0+y(1)

>hatchposition
{
<gravity [xh+offset, yh, 0]
<pointxyz [x1+offset, y1, 0]
}
sys(1111)=0 'turn this puppy off, a performance drain otherwise

>sethandle
{
<pointxyz [x1+offset, y1, 0]
}

>dragmove
{
<pointxyz [x1, y1, 0]
}

'optional conversion
'>vectorconvert
'{
'}

sys(80)=0
end