News:

Please note new Forum URL: forum.designcad.com

Main Menu
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.

Bidirectional arc

Started by bdeck, November 22, 2008, 08:58:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bdeck

Drawing a clockwise arc has never been difficult, but it has always taken far more effort than it should.

This macro works just like the center/begin/end arc command, except that prior to the final point it calls for a point to indicate the desired direction. It does in a single command what would otherwise take 3 separate operations.

I assign it to the "a" key and use it as a total replacement for the arc command.

Directions are displayed in the status bar.


BD

Edit 11/22:  added SelectOnly constraint to the Extend command
Edit 12/08/08:   corrected typo changing "z(1)-z(2)" to "z(1)=z(2)"          
Edit 12/11/08:   added "z(3)=z(2)" and "z(1)=z(3)"  tests
Edit 12/12/08    added "sys(470)=1"

'arcbi.d3m   Bidirectional arc macro  11/08  brent deck
'Creates a arc which can extend clockwise or counterclockwise from starting point.
'
'Set 4 points
'     1= arc center
'     2= starting point for arc
'     3= arc direction
'     4= end angle of arc
'
' Mainly 2d, but works in 3d if confined to a plane.
'
'

Alias CA_SPANANGLE  &H0305
Alias ENT_POINT  &H010E  


dim x(5), y(5), z(5)
ne=sys(9)
sys(1) = 0
sys41=sys(41)    
sys(41)=0
sys242=sys(242)
sys(470)=1

gosub archive    ' archive current selection, if any

>deselect
{
}

Setpoint "Set 4 points for  1) arc center, 2) starting point, 3) direction, 4) end angle", 3

If Sys(1) < 3 Then goto cleanup

for j = 1 to 3                  
  pointval x(j), y(j), z(j), j             'store point values
next j

sys(36)=2

>arc4
{
<Type 0
<Radius -1
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(2), y(2), z(2)]
<Pointxyz [x(3), y(3), z(3)]
}

if sys(9)=ne then goto cleanup

entity sys(9)
query CA_SPANANGLE, spangle
>eraselast      
{
}

if x(1)=x(2) and y(1)=y(2) and z(1)=z(2) then goto cleanup
if x(3)=x(2) and y(3)=y(2) and z(3)=z(2) then goto cleanup
if x(3)=x(1) and y(3)=y(1) and z(3)=z(1) then goto cleanup

if spangle < 180 then                                                  'draw counterclockwise arc

sys(36)=0

>arc4
{
<Type 0
<Radius 0
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(2), y(2), z(2)]
<incomplete
}

else                                                                       ' draw clockwise arc

sys(242)=1
>arc
{
<Type 0
<Radius 0
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(2), y(2), z(2)]
<Angle .1
}

       if sys(9)=ne then goto cleanup
       entity sys(9)
       query ent_point, 3, x(3), y(3), z(3)

>sethandle
{
<type 0
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(3), y(3), z(3)]
}
     
>move ' rotate the arc backwards .1 degree
{
<type 1
<Reference 0
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(2), y(2), z(2)]
}

sys(36)=0 ' turnoff silent mode
       entity sys(9)
       query ent_point, 2, x(2), y(2), z(2)

>Extend         ' now grab the clockwise end, and complete the arc                          
{
<SelectOnly 1        
<Pointxyz [x(2), y(2), z(2)] ' this would be a good place for an entity constraint
<incomplete
}
          if sys242=0 then sys(80)=0                                         ' deselect

endif

cleanup:
       sys(1)=0
       sys(242)=sys242
       sys(41)=sys41
       if ns>0 then
gosub restore
gosub regenlite
endif
sys(3) = clay
end


'subroutines follow


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

regenlite:           ' fast redraw of selected areas only
>move    
{
<type 1
<Reference 1
<Pointxyz 0 0 0
<Pointxyz 0,0,0
}
return


bdeck

#1
Here's an updated version that needs less housekeeping code.

By limiting the number of entities drawn to one (at a time), the macro is able to use "selectprevious" for housekeeping chores.

BD


Edit 12/08/08:    corrected typo changing "z(1)-z(2)" to "z(1)=z(2)",  etc             
Edit 12/12/08    added "sys(470)=1"



'arcbi.d3m  v. 2  Bidirectional arc macro  11/08  bdeck
'Creates a arc which can extend clockwise or counterclockwise from starting point.
'
'Set 4 points
'     1= arc center
'     2= starting point for arc
'     3= arc direction
'     4= end angle of arc
'
' Mainly 2d, but works in 3d if confined to a plane.
'
'

Alias CA_SPANANGLE  &H0305
Alias ENT_POINT  &H010E 

dim x(5), y(5), z(5)
ne=sys(9)            ' no of entities
sys(1) = 0            ' no of points set
sys41=sys(41)            ' archive rubberband type
sys242=sys(242)                  ' archive status of select-when-created flag
sys(470)=1

sys(41)=1            ' rubberband optional
Setpoint "Set 4 points for  1) arc center, 2) starting point, 3) direction, 4) end angle", 3
sys(41)=0            ' turn off rubberband

If Sys(1) < 3 Then goto cleanup

for j = 1 to 3                   
            pointval x(j), y(j), z(j), j             'store point values
next j

if x(1)=x(2) and y(1)=y(2) and z(1)=z(2) then goto cleanup
if x(3)=x(2) and y(3)=y(2) and z(3)=z(2) then goto cleanup
if x(3)=x(1) and y(3)=y(1) and z(3)=z(1) then goto cleanup

sys(36)=2

sys(242)=1   'turn on select at creation (deselects current selection set)

>arc4
{
<Type 0
<Radius -1
<Pointxyz [x(1), y(1), z(1)]
<Pointxyz [x(2), y(2), z(2)]
<Pointxyz [x(3), y(3), z(3)]
}

if sys(9)=ne then goto cleanup

entity sys(9)
query CA_SPANANGLE, spangle

if spangle < 180 then                       'draw counterclockwise arc
         n=3
else                                             ' draw clockwise arc
       n=2
endif

entity sys(9)
change ca_spanangle, .1
update
query ent_point, 3, x(3), y(3), z(3)

sys(36)=0                              ' turn off silent mode

>Extend                          ' now grab the clockwise end, and complete the arc                           
{
<SelectOnly 1         
<Pointxyz [x(n), y(n), z(n)]        ' this would be a good place for an entity constraint
<incomplete
}

cleanup0:
sys(1)=0
>selectprevious                                ' restore prior selection set, if any
{
}

        IF (sys(9)>ne) THEN
            entity sys(9)
            if n=2 then change ent_point,3, x(2), y(2), z(2)         'move point back .1 degree
            if sys242>0  then change ent_selected 1
            update
        endif

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