Segit version 3 (Segment a curve or arc to a user controlled number)

Started by prl, February 01, 2014, 06:26:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prl

With reference to this topic.  http://forum.designcad.com/index.php?topic=5367.msg35858#msg35858


Also attached is a zip file with a self-contained demo movie with the sample file used for testing this code.



'Program: segitv3.d3m (segment it version 3)

'2/7/2014 - v3 using the original curve for new point matching
'2/1/2014 - v2 added looping feature, layer destination, and vector or curve option per Phil request.


'  - there is a bug in the query/change dcadalias.d3i approach when reading coordinates if the user
'    uses the origin command during a DC session.  This doesn't happen with the older method of using
'    pointval to read the points.

'general notes:
'  - converts a curved line or circular arc into a segmented line or segmented curve


'DC Segment command behavior notes:
'      curves - the DC segment command converts a curve to a series of straight line vectors that may
'      have more than one two point line per segment. This routine uses only the first and last point of
'      each segment should it consist of more than two points

'      circular arcs - the segment command converts a circular arc to a segmented circular arc.
'      This routine deals with circular arcs by taking the beginning and end points of the arc
'      and uses the points to draw a two point line (a chord).


dim px(1000), py(1000), pz(1000)

laydest = 1 'default unless user enters a new layer number
input "Number of segments:", ndiv
input "Destination layer number for new segmented lines or curves: (default is layer 1) ", laydest
input "Enter letter for type of segmented line, V for vector or C for curve: (default is vector)) ", vtype$


here:
sys(1116)=0
sys(1)=0
sys(80)=0
start = sys(9)

setpoint "This routine keeps the original curve. Set one point on curve or circular arc to segment", 1

if sys(1)=1 then
  >PointSelect
  {   
    <Type 1
    <UsePresetPoints
  }
else
   precision 0
   message "Reminder: Segmented line or curve is on layer", laydest
   END 
endif

if sys(80)=0 then
  Message "Nothing selected. . . routine will END, press any key"
  END
end if

sys(36)=2

'copy original curve to clipboard, the DC segment command will destroy it
>SetHandle
{
  <Pointxyz 0, 0, 0
}
>Copy
{
}

>Segment
{
  <segment [ndiv]
  <setpointanddirection 0
  <UsePresetPoints
}
 
gosub FixSegments

sys(80)=0
sys(1)=0
sys(36)=0
regen

goto here
End


'subroutines follow
FixSegments:
sp1 = start

  >line
  {
  <layer [laydest]
  for j = sp1 to sys(9) 
    entity j
   
    epoints = sys(1)
     
    if sys(90) = 1 then 'vector, get first and last points
      pointval ptX1, ptY1, ptZ1, 1
      pointval ptX2, ptY2, ptZ2, epoints
    endif
 
    if sys(90) = 16 then 'circle or circular arc, get second and third points
      pointval ptX1, ptY1, ptZ1, 2
      pointval ptX2, ptY2, ptZ2, 3 
    endif
     
    'now draw two point line
    <pointxyz [ptX1,ptY1,ptZ1]
    <pointxyz [ptX2,ptY2,ptZ2]

    getattr j, type
    putattr j, type, 1
       
  next j
  }
  'This erases the DesignCAD segmented line
  >erase
    {
    }
                                           
  'Store the points of the newly segmented vector and then also erase it
  lent = sys(9)
  entity lent

  'store the points for the new line
  npoints = sys(1)
  for i = 1 to npoints
    pointval px(i), py(i), pz(i), i
  next i

  >eraselast
  {
  }
 
  'restore the copy of the orginal curve or arc so the new curve will have something to follow
   >paste
   {
    <type 1
    <pointxyz 0,0,0
   }

  'now draw the new line or curve and have it mate to the original curve using the line snaps
  if vtype$ = "C" or vtype$ = "c" then
    >curve
    {
    <layer [laydest]
    for i = 1 to npoints
        <linesnap [px(i), py(i), pz(i)]
    next i
    }
  else
    >line
    {
    <layer [laydest]
    for i = 1 to npoints
        <linesnap [px(i), py(i), pz(i)]
    next i
    }
  endif
 
Return

minstrel

"Hartelijk bedankt" :)

PRL, it's always amazing to see the 'feats' you produce with these codes...makes me wonder though, are you also as 'gifted' in 'Ruby' scripting?

prl

Quote from: minstrel on February 02, 2014, 01:32:32 AM
"Hartelijk bedankt" :)  . . .  are you also as 'gifted' in 'Ruby' scripting?

Thanks minstrel.   Sorry, a newbie with Ruby.

Dr PR

prl,

I have beenn using your segit version 2 macro quite a biit and I have found a problem. See the attached image.

The blue curve is the original - it has 11 points.

I wanted to use it for the curve for an extrusion along the curve and needed more points to get a smoother extrusion. I ran the macro and assigned 33 points.

The highlighted curve is the result. It clearly doesn't follow the original curve.

I have attached a file with the two curves for you to play with. Note: These curves were extracted from the original file, so you will not be working in the original environment.

Phil
DesignCAD user since 1987

prl

#4
Quote from: Dr PR on February 06, 2014, 08:59:17 PM
I have beenn using your segit version 2 macro quite a biit and I have found a problem. See the attached image.

Interesting curve.  The problem stems with the DC segment command.  It is moving the control points.  You can do it (using the segment command) manually and see the problem.

The original control points also move if you take the curve and simply convert to vector.  I have no idea why this curve would cause that.  I'll give this all some thought.


Later after having thought about it a bit:  Phil, I made a new version segitv3.  It is above in the first post.  I replaced the original code.  Try that and see what you think.

Dr PR

prl,

Whatever you did fixed it, at least for that curve.

I often create curves like this (the sheer line of a boat) that twist in all three dimensions. They cause "Extrude Along A Curve" to do really strange things. I wonder if that problem is related to moving the control points?

Thanks. Your macro is really coming in handy. I assigned it to a button on my custom tool bar. I have bothered to do that for only five functions so far.

Phil
DesignCAD user since 1987