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.

door placement macro

Started by bdeck, May 19, 2007, 03:30:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bdeck

This macro first duplicates a selection having 2 handles, to a target specified by two points. It then gives the user the option to accept or flip the result about an axis defined by those two points.

Aside from sticking door symbols into a floorplan, what else can it do?

Macro goes through some gymnastics derived from trial and error to keep handles in place, work with multiple selections and symbols, and avoid corruption with any subsequent undo.

This one works on v17.2, but fails on  v14.

Considering how little it does, it seems rather comlex. Anybody got a better way?



' doorstick.d3m  5/17/07
'
' With a selection having 2 handles exposed, run macro.
'
' Set 2 points on the target line:
'     1  target point for duplicate
'     2  alignment point for placement
'
'  Set a 3rd point to flip, or hit a key to accept, F3 to repeat.
'
'  Not good in preset point mode
'
' Could be useful for placing doors on a floorplan.
' 
' Note that sys(36) prevents dialog box cleanup errors.


sflag=sys(36)    ' archive silent
sys41=sys(41)    'archive rubberband style
sys38=sys(38)    ' archive text mirrro
sys242=sys(242)  ' archive selecton copy mode

again=1
do while again =1   
again=0

gosub seesel            'first, archive existing selection

if sys(80) <1 then end (if no items selected)
nts0=sys(9)        'no of ents in drawing

if sys(1)<>2 then                  'use correctly set points
      sys(1)=0
      Sys(41) = 1  'set rubber band style
      setpoint "Set 2 points Target,  Axis" 2
endif

if sys(1)<>2 then goto cleanup

gottem:
   sys(36)=1
   pointval x1 y1 z1 1
   pointval x2 y2 z2 2

   sys(38)= 0         'do not mirror text

   sys(242)=0
        >Duplicate    ' copy the source to the target line
{
<Reference 0   
<Type 1   ' 1 = fixed scale]
<Pointxyz [x1, y1, z1]
<Pointxyz [x2, y2, z2]
        }

   sys(242)=sys242
   
   Print "Press any    KEY to accept,   CLICK to flip,    ESC to undo,   F3 to accept and repeat"
   anykey kg
      ' message kg    ' learn keycodes
 
gosub newsel   ' select it here to make symbol points clickable
if kg > 1 then
        if kg=27 then
   >Undo
   {
   }
        else
            if kg=114 then again = 1        ' repeat if F3 is pressed     
        endif
   else
         >Mirror
   {
         <Axis 4   'custom mirror
         <Type 0   'dont make copy
         <Pointxyz [x1, y1, z1]
<Pointxyz [x2, y2, z2]
   }     
           
          sys(242)=0  'dont select result    
           >Mirror             'restores makeCopy option
   {
         <Axis 4   'custom mirror
         <Type  1  ' make copy
         <Pointxyz -10000, 1,0
<Pointxyz -10000,2,0
   }
           sys(242)=sys242
   >Undo
   {
   }
           
   endif 
gosub resel
cleanup:
  sys(38)=sys38     
  Sys(41) = sys41
  sys(36)=sflag
  sys(1)=0     'clean up unused points

'REGEN  ' Does not appear necessary in v 17.2 non-preset point mode
loop   
end

seesel:                   'archive current selection handles
        xx1=sys(190)   
yy1=sys(191)
zz1=sys(202)
xx2=sys(192)
yy2=sys(193)
zz2=sys(203)
return

resel:                   'reselect the original selection and reset the original handles

>SelectPrevious  ' This must me magic
   {
   }

>SetHandle               ' reset the handles in case original was a multiple selection
{
<Pointxyz [xx1,yy1,zz1]
<Pointxyz [xx2,yy2,zz2]
<Type 0
}

sys(190) =xx1             'restore handles to active duty
sys(191) =yy1
sys(202)=zz1
sys(192)=xx2
sys(193)=yy2
sys(203)=zz2   
return

newsel:  ' use this instead of sys(242) to prevent deactivation of handles by undo
       Alias ENT_SELECTED  &H010C 
>Deselect
   {
   }
nts2=sys(9)
if nts2>nts0 then
nts1=nts0+1
for i=nts1 to nts2
entity i
change ent_selected, 1
next i
        update
         endif
return