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.

How can I move solids from within a macro?

Started by Dempsey, August 16, 2008, 07:32:18 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

bdeck

#15
Hi Prl,

Your recollection is correct.

Here's a little macro to illustrate the problem reselecting solids by entity number when the selection set was originally recorded with getselect.

After reselecting the exact same entity numbers as the original selection set, using either change or putattr, the move command gives flaky results.

This needs fixing in DC, but in the meantime, thanks for your executable. ( I'm on the road, and havent had a chance to test it on 15.3)

Also a way to use change ent_point on solids without first exploding would be very helpful. Got any tricks up your sleeve?

Regards,

BD


'mover0.d3m
'demo to show solid selection problems with basiccad
'select a solid (try a cone first)
' run the macro all three ways

Alias ENT_SELECTED  &H010C 

n=sys(80)
if n=0 then
print "nothing selected"
anykey a
end
endif

dim ent(1+n)

for i=1 to n
    getselect i,ent(i)   ' archive the selection list
next i

input "choose move method  0 = current selction, 1 = reselect using putattr, 2= reselect using change :  "

mm

if mm = 1 then
  >deselect
  {
  }

  for i=1 to n
     getattr ent(i),t
     putattr ent(i),t,1   
  next i
endif

if mm = 2 then
  >deselect
  {
  }

  for i=1 to n
     entity ent(i)
     change ent_selected 1
     update
  next i
endif

dx=5
dy=5
dz=0

>move
{
<type 1
<Reference 1
<Pointxyz 0 0 0
<Pointxyz [dx,dy,dz]
}


print "hit any key to undo and end macro"
anykey a

>undo
{
}

end


 


bdeck

#16
Hello All,

On further review, the problem in my code above is not in putattr, or change ent_selected, or move.

It appears to be in sys(80) and getselect.

I tried making an alternative selection list using sys(9) and query ent_selected. (getattr also works as shown below)

When the items on that list were reselected using either putattr or change ent_selected, the move executed correctly.

'mover1.d3m
'demo to show fix for solid selection problems with basiccad
'select a solid (try a cone first)
' run the macro all three ways

Alias ENT_SELECTED  &H010C 

ne=sys(9)    ' no of entities in drawing
n=sys(80)    ' no of selected entities
if n=0 then end

dim ent(1+n),entsel(1+ne)

input "choose move method  0 = current selction, 1 = reselect using putattr, 2= reselect using change :  ",  mm

for i=1 to ne                     '  *****  archive selection list  *****
    getattr i,t,entsel(i) 
next i

if mm = 1 then

   >deselect
  {
  }

     for i=1 to ne
        if entsel(i) then
           getattr i,t
           putattr i,t,1 
        endif
  next i
endif

if mm = 2 then
 
  >deselect
  {
  }

  for i=1 to ne 
    if entsel(i) then
        entity i
        change ent_selected 1
        update
    endif
  next i
endif

dx=5
dy=5
dz=0

>move
{
<type 1
<Reference 1
<Pointxyz 0 0 0
<Pointxyz [dx,dy,dz]
}

end
 

prl

Quote from: bdeck on August 26, 2008, 12:56:36 AM
It appears to be in sys(80) and getselect.

Bd, you found the problem source!!!!  Draw a solid cube and select it.  There should be 5 entities (2 planes, 1 grid header, 2 grid lines).  Sys(80) only reports 3. I wish you worked as a programmer for IMSI.

.
.
.
dim ent(1+n),entsel(1+ne)

Message "Total entities", ne
Message "Total entities selected", n
.
.
.


prl

Dempsey, based on the excellent sleuthing by Bd, here is how you can select solids using only basiccad. This is based on the previous code I posted.

Once you have the solid id list made, you have to search the entire drawing database (the italicized code) to find matching solidids, not the selection set.

'now using basiccad, select each solid individually and do something with selection
for j = 1 to scount
  sys(1) = 0
  sys(80) = 0
  'select only entities with matching solid id
  for jj = 1 to sys(9)
    getattr jj, type, select, laynum, groupid, red, green, blue, solidid
    if solidid = SolidIdList(j) then putattr jj, type, 1
  next jj

  gosub DempseyCode
next j


Thanks to Bd. 

Dempsey

bdeck, prl,

Thanks for the help. I had already figured out that I needed to select also the grid lines as I mentioned in my reply earlier (http://forum.designcad.com/index.php?topic=1535.msg7978#msg7978). I just did not have time this weekend to do any coding. After that I plan on also including groups, layered groups and blocks.
Dempsey

prl

Quote from: Dempsey on August 26, 2008, 08:22:30 PM
Thanks for the help. I had already figured out that I needed to select also the grid lines

Dempsey, reading your post again I see you did find the entity 33 selection bug, I just didn't get it.

Kudos to you and Bd for alerting me to this sys(80) and getselect bug. Learned something again.

DrollTroll

Sorry, I had forgotten about this behavior.

I quote from the Developer's Guide:

QuoteSimilarly, a solid is a set of separate entities that all have the same Solid ID in common. Like a group, an entire solid can be selected at once by selecting any entity that is part of the solid. A solid can consist of grids, planes, lines, circles, or whatever - DesignCAD has no mechanism for verifying whether the solid makes any physical sense.

You can think of a solid as a special kind of group - a group can contain multiple solids (since the Solid ID and the Group ID are separate items), but a solid can't contain other solids.

Grids are in a special category of their own: they are composite objects. Every grid consists of a Grid Header (type 32) and a number of Grid Lines (type 33). The header and its associated grid lines are all separate entities, but they are considered to be part of the same object. This is why, in the macro MakeXYZ.d3m, we had to make a special case for Grid headers. Sys(80) returns the number of selected objects, not the number of selected entities. (Note that the number of "points" claimed by the grid header is actually the number of "children" grid lines to follow. All "children" of a particular grid header have the same number of points.)

So, for example, if you were to start a new drawing, create a 3D box using the Box command, select the box, then check the value of Sys(80), you would find that you had 3 objects selected. However, if you check the value of Sys(9), you would find a total of 5 entities. What is the reason for the difference? The box, a solid, consists of three objects: a front face (plane), a back face (plane), and the surface between (grid). The grid itself,  however, consists of three entities: a grid header, and two grid lines. Thus, you have five entities: (1) front plane, (2) back plane, (3) grid header, (4) grid line #1, and (5) grid line #2.

At the risk of drowning the message, I am attaching an ancient version of MakeXYZ (note: you need both the d3i and d3m files in the same folder) -- it doesn't deal with all the new entities, but it demonstrates how to get info on grid lines via BasicCAD. Pay attention to the test for type 32, and the DoGrid subroutine.
25 years with DesignCAD

prl

Quote from: DrollTroll on August 28, 2008, 07:25:59 AM
Sorry, I had forgotten about this behavior.

So it's not a bug but . . . . the user clicks a solid cube and 5 entities are selected. The basiccad user tries to store that same selection set and only gets a partial list, 3 entities,  and has to jump through numerous do loops to find the missing selected entities.  What nonsense.

Why was this implemented this way? To save storage because of the number of grid lines?

bdeck

#23
Quote from: prl on August 28, 2008, 01:46:56 PM
So it's not a bug but . . . .

Hi Prl,

WRT box solids:

I don't mind sys(80) not reporting all five entities, but why 3 ??  Why not just 1 ??

And when that one entity is subsequently selected, why not select all five automatically by default, just as in pointselect?

I haven't thought this through, but it seems to me that either 1 or 5 would be OK. But the benefit of 3 is, shall we say, not immediately obvious.

At any rate, it's good to see we have a newly active programmer on this forum, who is finding these things we have missed for years.

BD

Dempsey

#24
1, 3 or 5 entities included in SYS(80), we still have to select all 5 entities to do a proper selection from within BasicCAD. Solids I have already working.

I am now working on groups with type 34. That gets complex when multi-level groups are selected, especially because BasicCAD does not support recursion. I have to consult my gray cells how I did it some 30 years ago ???

I like to suggest that we need two extra statements or functions in BasicCAD:

  • One that selects all entities of a solid. Parameter is the solid ID.
  • And one that selects all entities of a subgroup or main group. Parameter is the subgroup ID of the to be selected subgroup, or main group ID of the multi-level group to be selected.
Dempsey

prl

Quote from: Dempsey on August 28, 2008, 09:11:11 PM
I am now working on groups with type 34. That gets complex when multi-level groups are selected, especially because BasicCAD does not support recursion. I have to consult my gray cells how I did it some 30 years ago ???

Dempsey, your work and interest in basiccad is refreshing to read.  Regarding multi-level groups, you are aware the IMSI implementation for nested groups (type 34) is unstable.  Dr and myself have pointed this out before in numerous examples. In case you are trying to solve the unsolvable.

Dempsey

prl, thanks for reminding me about the nested groups problems; I'll have to re-read those topics.

In the small scale tests I have done so far the nested groups are structured as documented, and I was able to properly select all entities of nested groups. The objection I have is that it is not straight forward. It would have been so much easier when the group ID, i.e. SYS(94), returned by functions such as GetAttr is the group ID of the highest level group.
Dempsey

Dempsey

MORE PROBLEMS.

I solved all problems (I thought) and have done all my coding, but the final move of a solid gives crazy results. I create a test macro to proof that selecting solids using "PUTATTR ent, type, 1" does not work for some reason, while selecting a solid using PointSelect does work.


'
' ====== TEST 1 -- use existing selected box
'
'   save selected entities, and verify that one solid is selected
'
  n = sys(80)
  if n <= 0 then
    message "Nothing selected, macro will end"
    end
  end if
  dim ent(n)
  dim type(n)
  dim solid(n)
  for i = 1 to n
    getselect i, ent(i)
    getattr ent(i), type(i), select, laynum, group, red, green, blue, solid(i)
  next i
  sld = solid(1)
  if sld <= 0 then
    message "you must select one box, macro will end"
    end
  end if
  fmt1$ = "(1) box min/max before move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out1$, fmt1$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
'
'   deselect and then reselect all entities of the solid
'
  >Deselect
    {
    }
  sys(80) = 0
  window (10,120)
  print "TEST 1 -- Reselected entities of solid:", sld
  for i = 1 to n
    if solid(i) = sld then
      putattr ent(i), type(i), 1
      print "entity:", ent(i), "type:", type(i)
      if type(i) = 32 then
        entity ent(i)
        if sys(99) > 0 THEN
          for k = ent(i)+1 TO ent(i)+sys(99)
            getattr k, typegrid
            putattr k, typegrid, 1
            print "entity:", k, "type:", typegrid
          next k
        end if
      end if
    end if
  next i
  print "any key to continue"
  anykey
  wclose
'
'   now move the solid
'
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel 7,3,1
    }
  fmt2$ = "(2) box min/max after 1st move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out2$, fmt2$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel -7,-3,-1
    }
  fmt3$ = "(3) box min/max after 2nd move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out3$, fmt3$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
'
'   report results
'
  window (10,140)
  print "TEST 1 -- Saved box entities, deselected selection, reselected all entities, and moved it twice"
  print out1$
  print out2$, "X shifted +7, Y +3, and Z +1; is that correct?"
  print out3$, "X shifted -7, Y -3, and Z -1; is box at position (1) again?"
  print "any key to exit"
  anykey
  wclose
'
' ====== TEST 2 -- delete box, create new box and select it
'
'   draw a box and select it
'
  >box
    {
      <color 0, 0, 255
      <layer 1
      <pointxyz 0, 0, 0
      <pointrel 5, 3, 1
    }
  >pointselect
    {
      <type 0
      <pointxyz 0, 0, 0
    }
'
'   now move the solid
'
  fmt1$ = "(1) box min/max before move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out1$, fmt1$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel 7,3,1
    }
  fmt2$ = "(2) box min/max after 1st move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out2$, fmt2$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel -7,-3,-1
    }
  fmt3$ = "(3) box min/max after 2nd move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out3$, fmt3$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
'
'   report results
'
  window (10,140)
  print "TEST 2: Deleted original box, created new box, and moved it twice"
  print out1$
  print out2$, "X shifted +7, Y +3, and Z +1; is that correct?"
  print out3$, "X shifted -7, Y -3, and Z -1; is box at position (1) again?"
  print "any key to continue"
  anykey
  wclose
'
' ====== TEST 3 -- use previous created and selected box
'
'   save selected entities, and verify that one solid is selected
'
  n = sys(80)
  if n <= 0 then
    message "Nothing selected, macro will end"
    end
  end if
  dim ent2(n)
  dim type2(n)
  dim solid2(n)
  for i = 1 to n
    getselect i, ent2(i)
    getattr ent2(i), type2(i), select, laynum, group, red, green, blue, solid2(i)
  next i
  sld = solid2(1)
  if sld <= 0 then
    message "you must select one solid, macro will end"
    end
  end if
  fmt1$ = "(1) box min/max before move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out1$, fmt1$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
'
'   deselect and then reselect all entities of the solid
'
  >Deselect
    {
    }
  sys(80) = 0
  window (10,120)
  print "TEST 3 -- Reselected entities of solid:", sld
  for i = 1 to n
    if solid2(i) = sld then
      putattr ent2(i), type2(i), 1
      print "entity:", ent2(i), "type:", type2(i)
      if type2(i) = 32 then
        entity ent2(i)
        if sys(99) > 0 THEN
          for k = ent2(i)+1 TO ent2(i)+sys(99)
            getattr k, typegrid
            putattr k, typegrid, 1
            print "entity:", k, "type:", typegrid
          next k
        end if
      end if
    end if
  next i
  print "any key to continue"
  anykey
  wclose
'
'   now move the solid
'
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel 7,3,1
    }
  fmt2$ = "(2) box min/max after 1st move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out2$, fmt2$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
  >Move
    {
      <Reference 1
      <type 1
      <pointxyz 0,0,0
      <pointrel -7,-3,-1
    }
  fmt3$ = "(3) box min/max after 2nd move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out3$, fmt3$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)
'
'   report results
'
  window (10,140)
  print "TEST 3 -- Saved new box entities, deselected selection, reselected all entities, and moved it twice"
  print out1$
  print out2$, "X shifted +7, Y +3, and Z +1; is that correct?"
  print out3$, "X shifted -7, Y -3, and Z -1; is box at position (1) again?"
  print "any key to exit"
  anykey
  wclose
  regen
end



  • Start an empty drawing and create a box of size X=5, Y=3 and Z=1, at location (0,0,0).
  • Run the macro.
  • You get several windows with results for tests 1, 2, and 3.

Interesting results isn't it? Did I make a coding error somewhere? Before I embark on rewriting my main macro using PointSelect, I like to make sure that the current PUTATTR approach is a dead horse, and really like to know why it does not work.



Dempsey

bdeck

#28
Hi Dempsey,

Here is another wierd behavior you have uncovered.

If you want DC to ignore handles, apparently you have to give it a handle to ignore.

Move-by-reference is clearly failing in your example.

Adding a single handle somewhere prior to the move statements (even though the handle is not used) seems to fix the problem.

This works fine for me, because I generally locate handles slightly offscreen to avoid screen clutter.

This appears to be a bug for DT's attention.

("Reference 0" moves using handles also work).

BD




>sethandle
{
<pointxyz 1880,8870,9090           'any arbitrary handle will do
}
  >Move
    {
     <type 1
      <Reference 1
      <pointxyz 0,0,0
      <pointxyz 7,3,1
    }
  fmt2$ = "(2) box min/max after 1st move x:(%6.3f,%6.3f) y:(%6.3f,%6.3f) z:(%6.3f,%6.3f)"
  format out2$, fmt2$, sys(196), sys(198), sys(197), sys(199), sys(200), sys(201)

>Move
    {
      <type 1
      <Reference 1
      <pointxyz 0,0,0
      <pointxyz -7,-3,-1
    }



Heres an alternative to sys(242) for selectiing your box:



sys9=sys(9)        'archive entity count
 
  >box
    {
      <color 0, 0, 255
      <layer 1
      <pointxyz 0, 0, 0
      <pointrel 5, 3, 1
    }

  for ent=sys9+1 to sys(9)     ' select all recently drawn entities
getattr ent,t
             putattr ent,t,1
   next ent


DrollTroll

Essentially, the PutAttr statement doesn't create a selecction handle when you use it to select one or more entities. So yes, you need to manually set a selection handle if you're going to move or copy objects.

Statements don't usually have the full range of "visual" effects that the commands do.

Yes, the documentation should be clearer on this.
25 years with DesignCAD