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.

Select by Solid ID

Started by Garry K, January 05, 2013, 04:13:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Garry K

Is there any easy way to select a solid when you know the Solid ID?

Do you have to use sys(9) and traverse all of the entities?

I am looking for something like SelectBySolidID.



prl

Unfortunately no.  You've have to cycle the database.

'you already know the solidid

for m = 1 to sys(9)
       getattr m, type, select, laynum, group, rc, gc, bc, id
       if id = solidid then putattr m, type, 1
next m

Garry K

Just as I thought. Too bad - as a drawing becomes large - traversing the entire database increases.

With my cabinet maker macro - I have switched to converting to blocks after each cabinet has been built, rotated, mirrored and moved. I now have to store a bunch of information in several arrays so that I can later find the solid and convert it into a block.

Now I'm back to the Z zero problem as this code is not working as expected. Perhaps another pair of eyes can help.

The handles for the blocks are not being set to 0,0,0

'------------------------------------------------
' Iterate and move entities
'------------------------------------------------
IterateAndMove:

' clear out array
For k = 1 to index
  _id(k) = 0
Next k

' turn on layers for final placement of cabinets
For j = 2 To 11
  Layer(j) = 6
Next j

' move cabinet parts into final layers
max = Sys(80)
For i = 1 To max
  GetSelect i, j
  GetAttr j, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid
  elayer = elayer - 10
  PutAttr j, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid

  ' need to store the solidid
  For k = 1 to index
    If ( _id(k) = 0 AND elayer = _layers(k) AND egreen = _part(k) AND eblue = _block(k) ) Then
      _id(k) = esolid
    End If
  Next k
Next i

' create the blocks
max = Sys(9)
For k = 1 To index
  solidid = _id(k)

  If solidid > 0 Then
    >DeSelect
    {
    }
    Sys(3) = _layers(k)

    For m = 1 To sys(9)
      getattr m, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid
      if esolid = solidid Then
        putattr m, etype, 1
      End If
    Next m
    block$ = _names$(k)
    Gosub DoDefineBlock
  End If
Next k

>DeSelect
{
}

' turn off final layers in preparation for next cabinet
For j = 2 To 11
  Layer(j) = 0
Next j

' reset index - next cabinet will make use of arrays.
index = 0
Return

'------------------------------------------------
' Do Define Block
'------------------------------------------------
DoDefineBlock:
>SetHandle
{
  <Pointxyz 0, 0, 0
  <Pointxyz 0, 0, 0
  <Pointxyz 0, 0, 0
  <Type 1
}

>BlockDefine
{
  <Name [block$]
  <WaitForOK 0
  <Type 0
}

Return



prl

.
.
.

'------------------------------------------------
' Do Define Block
'------------------------------------------------
DoDefineBlock:
>SetHandle
{
  <Pointxyz 0, 0, 0
  <Pointxyz 0, 0, 0
  <Pointxyz 0, 0, 0

  <Type 0
}

>BlockDefine
{
  <Name [block$]
  <WaitForOK 0
  <Type 0
}

Return

prl

Garry,  you have some dangerous code.  The GetSelect i variable will skip grid lines.   So with the PuttAttr statement you are moving your solids from elayer to elayer - 10  . . . but your grid lines aren't going along for the ride.

.
.
.
' move cabinet parts into final layers
max = Sys(80)
For i = 1 To max
  GetSelect i, j
  GetAttr j, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid
  elayer = elayer - 10
  PutAttr j, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid
.
.
.

Garry K

OK

If I traverse everything I want to only move from layer 12 through 19 and have them move to layer 2 through 9

Is this ok?

max = Sys(9)
For i = 1 To max
  GetAttr i, etype, eselect, elayer, egroup, ered, egreen, eblue, esolid
  if elayer > 11 AND elayer < 20 Then
    elayer = elayer - 10
    PutAttr i, etype, eselect, elayer
    For k = 1 to index
      If ( _id(k) = 0 AND elayer = _layers(k) AND egreen = _part(k) AND eblue = _block(k) ) Then
        _id(k) = esolid
      End If
    Next k
  End If
Next i

Garry K

One more thing.

Is there a way to add some attribute that is part of the solid that I can use?

prl

Quote from: Garry K on January 06, 2013, 08:37:33 AM
If I traverse everything I want to only move from layer 12 through 19 and have them move to layer 2 through 9
Is this ok?

Looks like this should catch everything.

Quote from: Garry K on January 06, 2013, 08:45:11 AM
Is there a way to add some attribute that is part of the solid that I can use?

As you are looping, the entity statement will let you add or read  the string field of each entity  - sys$(300).    Only thing is sys$(300) tends to slow down the loops.



Garry K

Still foiled - If I rem out the code that is directly after ' Create the Blocks
up to the >Deselect then the cabinet looks fine albeit no blocks.