DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Faux parallel to ellipse or elliptical arc

Started by bdeck, March 28, 2009, 03:19:22 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

bdeck

The attached macro works similarly to the "="  command.

But instead of creating true parallels, it scales the copy proportionally.

Useful for illustration and isometric 2d work.

The optional  selected only query message may be deleted if desired.

BD

Note: This version works fine in versions 14-19,  but has selection persistence issues in dc 18 and 19. See following post.


Minor edits on 3/30/09


'pe.d3m   parallel ellipse command  3/09  bdeck

'creates a scaled copy of an ellipse or eliptical arc so that it appears parallel to original
' works like = command

Alias ENT_NPTS  &H010D
Alias ENT_POINT  &H010E 

dim x(10),y(10),z(10)

ne0=sys(9)                        ' no of entities
sys(1) = 0                         ' no of points set
sys242=sys(242)                 ' archive status of select-when-created flag
sys41=sys(41)
sys(41)=1                ' set rubberband style
ns=sys(80)
soflag=0                 ' initial value of selected only flag for parallel command

if ns>0 then                                        ' Optional message may be deleted if desired
Sys(1027) = 4 'Yes/No MessageBox style
message " Selected Only? "
if sys(1028)=6 then soflag=1
            Sys(1027) = 0 'OK MessageBox style    *** edit 1
endif

Setpoint "Set a point on ellipse and one on destination", 2
if sys(1)<>2 then goto cleanup
pointval xe,ye,ze,1
pointval xL2,yL2,zL2,2
sys(1)=0
>LineSnap
{
<pointxyz [xe,ye,ze]
}
Getxy xes, yes, zes                                ' point on ellipse

>Extend                     
{
<selectonly [soflag]       'Set this flag here for the parllel command
<null
}

sys(242)=1
sys(36)=2

>Parallel                       ' draw a duplicate elipse of same size using parallel command at 0 distance
{
<Pointxyz [xes,yes,zes]
<Pointxyz [xes,yes,zes]
}

if sys(9)=ne0 then goto cleanup

getselect 1, npar
getattr npar, t

if (t<>7) and (t<>2) then
message "Entity picked is not an elipse or eliptical arc"
>undo                                                                                                         '   *** edit 1
{
}
>selectprevious          ' undo does not restore prior selection in this instance      
{
}
goto cleanup
endif

entity npar                                      ' measure the elipse
query ent_npts, nps
for i=1 to nps
query ent_point,i,x(i),y(i),z(i)
next i

>movetoback                   'lowest items will be used in trim ops
{
}
>selectprevious                              'preserve selection set
{
}


xL1=x(1)      ' radial line starts at center of elipse
yL1=y(1)
zL1=z(1)

sys(242)=1
>line
{
<Pointxyz [xL1,yL1,zL1]
<Pointxyz [xL2,yL2,zL2]
}

if sys(9)=ne0 then goto cleanup

>movetoback                   'lowest item will be trimmed
{
}
>selectprevious                                 'reselect prior selection
{
}

>Trim1
{
<Pointxyz [xL2,yL2,zL2]
<Pointxyz [xes,yes,zes]
}

nline=sys(9)                  ' trimmed line is now at the end of the list again
entity nline
query ent_point,1,x1,y1,z1
query ent_point,2,x2,y2,z2
>EraseLast
{
}
>pointselect            ' reselect the new ellise
{
<type 0
<Pointxyz [xes,yes,zes]
}

>movetotop              ' move the copied elipse back to the top
{
}

if (x1<>xL1) or (y1<>yL1) or (z1<>zL1) then          'check which end of line was trimmed
x2=xL1
y2=yL1
z2=zL1
endif

if abs(x2-x1)>abs(y2-y1) then                                 'determine linear scale factor
sf=abs((xL2-xL1)/(x2-x1))
else
if y2<>y1 then
sf=abs((yL2-yL1)/(y2-y1))
        else
if z2<>z1 then
sf=abs((zL2-zL1)/(z2-z1))
        else
message "infinitely small result, operation cancelled"
goto cleanup
endif
endif
endif

if sys(9)=ne0 then goto cleanup

sys(36)=0
entity sys(9)
for i=2 to nps                               ' scale the duplicate without creating a handle
x=x(1)+sf*(x(i)-x(1))
y=y(1)+sf*(y(i)-y(1))
z=z(1)+sf*(z(i)-z(1))
change ent_point i, x, y, z
next i
update

showresults:                  ' rapid redraw
>selectprevious     
{
}
if sys242=1 then
>selectprevious
{
}
endif

cleanup:
sys(242)=sys242
sys(41)=sys41
sys(1)=0
end



bdeck

#1
This version works equally well in all versions from 14 up.

Corrects selection persistence error of prior macro when running in DC versions 18 and 19.





'pe.d3m  V2  parallel ellipse command  3/09  bdeck

'creates a scaled copy of an ellipse or eliptical arc so that it appears parallel to original
' works like = command

' Version 2 eliminates error in preserving selection status.



Alias ENT_NPTS  &H010D
Alias ENT_POINT  &H010E 
Alias ENT_SELECTED  &H010C 

dim x(10),y(10),z(10)
sys(470)=1
ne0=sys(9)        ' no of entities
sys(1) = 0        ' no of points set
sys242=sys(242)          ' archive status of select-when-created flag
sys41=sys(41)
sys(41)=1                ' set rubberband style
soflag=0                 ' initial value of selected only flag for parallel command
ns=sys(80)
verno = left$(sys$(105),4)

if ns>0 then gosub archive


if ns>0 then                                        ' Optional message may be deleted if desired
Sys(1027) = 4 'Yes/No MessageBox style
message " Selected Only? "
if sys(1028)=6 then soflag=1
        Sys(1027) = 0 'OK MessageBox style    *** edit 1
endif

Setpoint "Set a point on ellipse and one on destination", 2

if sys(1)<2 then goto cleanup
pointval xe,ye,ze,1
pointval xL2,yL2,zL2,2
sys(1)=0
>LineSnap
{
<pointxyz [xe,ye,ze]
}
Getxy xes, yes, zes  ' point on ellipse


sys(242)=1
sys(36)=2

>Extend                     
{
<selectonly [soflag]       'Set this flag here for the parllel command
<null
}

>Parallel ' draw a duplicate elipse of same size using parallel command at 0 distance
{
<selectonly [soflag]
<Pointxyz [xes,yes,zes]
<Pointxyz [xes,yes,zes]
}

>Extend                     
{
<selectonly 0       'reset flag
<null
}

if sys(9)=ne0 then goto cleanup


getselect 1, npar
getattr npar, t

if (t<>7) and (t<>2) then
       
message "Entity picked is not an elipse or eliptical arc"
>undo                                                        '   *** edit 1
{
}
>selectprevious          ' undo does not restore prior selection in this instance      
{
}
goto cleanup
endif

entity npar      ' measure the elipse
query ent_npts, nps
for i=1 to nps
query ent_point,i,x(i),y(i),z(i)
next i

>movetoback                   'lowest items will be used in trim ops
{
}

xL1=x(1)      ' termporary radial line starts at center of elipse
yL1=y(1)
zL1=z(1)

sys(242)=1
>line
{
<Pointxyz [xL1,yL1,zL1]
<Pointxyz [xL2,yL2,zL2]
}

if sys(9)<ne0+2 then goto cleanup
nline= sys(9)

>movetoback                   'lowest item will be trimmed
{
}

>Trim1                             ' This does not appear to be affected by the soflag
{
<Pointxyz [xL2,yL2,zL2]
<Pointxyz [xes,yes,zes]
}

nline=sys(9)
entity nline
query ent_point,1,x1,y1,z1
query ent_point,2,x2,y2,z2
>EraseLast        ' erase the line
{
}

gosub sfcalc

sys(36)=0


entity 1
for i=2 to nps                              ' scale the duplicate without creating a handle
x=x(1)+sf*(x(i)-x(1))
y=y(1)+sf*(y(i)-y(1))
z=z(1)+sf*(z(i)-z(1))
change ent_point i, x, y, z
next i
change ent_selected,1
update

>MoveToTop
{
}

showresults:             

if sys242=0 then
>deselect
{
}
      if ns>0 then gosub restore
endif
regen   

cleanup:
sys(242)=sys242
sys(41)=sys41
sys(1)=0

end

sfcalc:
if (x1<>xL1) or (y1<>yL1) or (z1<>zL1) then 'check which end of line was trimmed
x2=xL1
y2=yL1
z2=zL1
endif
sf= sqrt(sqr(xL2-xL1)+sqr(yL2-yL1)+sqr(zL2-zL1))/sqrt(sqr(x2-x1)+sqr(y2-y1)+sqr(z2-z1))
if sf=0 then
message "infinitely small result, operation cancelled"
>erase
{
}
goto cleanup
endif
return

archive:      '  archive current selection set
if sys(80)>0 then
    ns=0
    ne=sys(9)
    dim entsel(ne+1)
    for i=1 to ne
       getattr i,t,sel
       entsel(i) = sel mod 2  ' nearest thing to a bitwise (AND 1) available in DC
       ns=ns+entsel(i)
    next i

    sys190=sys(190)    ' archive handles
    sys191=sys(191)
    sys192=sys(192)
    sys193=sys(193)
    sys194=sys(194)
    sys195=sys(195)
    sys202=sys(202)
    sys203=sys(203)
    sys204=sys(204) 
  endif
return

restore:    ' restore original selection set and handles
    if ns>0 then
       For i = 1 To ne   'Reselect all prior selected items
          if entsel(i) then
               Getattr i, type, sel
               if  sel <> 1 then  Putattr i, type, 1    ' eliminate prior selection flag for all selected ents 
           endif
        Next i
    endif
   
    >SetHandle
    {
<Pointxyz [sys190, sys191, sys202]
<Pointxyz [sys192, sys193, sys203]
<Pointxyz [sys194, sys195, sys204]
<Type 0
    }

return