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.

Working with Nested Groups

Started by Garry K, November 06, 2012, 06:40:07 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Garry K

I am writing cabinet software in C++ and I am using Design Cad to display 3D drawing s of the cabinets. I have version 16 and version 22.

The overall strategy is to have my cabinet software write a data file, use OLE to load Design cad, run a macro and read in the data file.

I am using Layer 1 as a work area and mostly work with 3D boxes. Once I am finished with the objects I move them into Layer 2, 3 or 4. Layer 2 is for the main cabinet. Layer 3 is for Door and Drawer fronts and Layer 4 is for drawer box parts.

Only layer 1 is editable and visible while do the work. Once all the parts for a cabinet are created I turn on layers 2, 3 and 4 and select all. Then I combine all the selected parts into a group.

So far so good - 1 cabinet built. What I want to do next is move and possibly rotate the cabinet and then move it into a different set of layers - possibly 5,6 and 7. Then I thought I could disable all of the layers except for Layer 1 my working layer and then create the next cabinet. etc etc.

Is there a way to move a nested group ( composed of 3 layers ) into a different set of 3 layers?
Do I have to explode the group after I moved and rotated it first?
Ultimately I wanted each cabinet to be a separate group and have all doors / drawers in one layer etc. etc.

Do I have to iterate through all the objects? If this is the case - perhaps I should assign a cabinet attribute to each and every part so that I can later select all the parts for a cabinet and re define as a group?

Suggestions any one?


Lar

#1
Normally groups are not associated with layers (you can have each member of a group on different layer) but the (first) trick here is the 'nested group container', which is 'invisible' to the user and cannot selected manually but could be with a macro.

You would have to select the whole group by clicking on it (use the >PointSelect command), which would get the container selected. You would then have to get the entity numbers of everything selected in an array. Since you are dealing with solids the entities involved will be the container (which is entity type 34, I think), Planes, Grid Headers and Grid Lines (the second trick).

You would then have to deselect all and then iterate through each entity by id number. Each iteration would check the entity type. If it is 34 (the ~assumed~ nested group container) you would place it on any of the new layers (using Query and Change). If not type 34, you would place on new layers depending on what layer they are now on. This includes the grid headers.

Now, and here's the 2nd trick... if the entity is a Grid Header you would have check its number of points. This number would indicate how many Grid Lines follow the Grid Header. You can't select Grid Lines but they always follow grid headers so you get the number of points of the header and iterate through that amount of entities that follow it to change the layer of the grid lines.

If you change the layer of the header and don't do this to change the layer of the grid lines you won't be able to snap to the points of the grid surface if the layer of the lines is off, and the points won't show in point select mode. If the layer of the lines is on but the header's is off you won't see the grid surface but if you gravity snap near enough to one of its points you would snap to it.

Lar

Garry K

Maybe there is an easier way. Can I do a trick like this.
Draw everything in my work area as before. But this time set very specific rgb values to temporarily group things.
r could be my target layer and g could be my cabinet number.

When I am finished creating a cabinet I will have moved all parts into say Layer 2. At which time only Layer 2 and work area that is now empty are visible and editable. Make a group - non nested. Move and or rotate the cabinet into place the move it to layer 3 using >ApplyLayer and then explode the group.

Continue this way until all cabinets are created, grouped, placed, rotated moved into Layer 3 and exploded.

Once all of the cabinets are completed - then iterate through all of the parts walking based on cabinet number  ( g ) moving the completed parts into the correct layer.

At this time can I select all parts for a single cabinet and then group them? Since they won't move after this grouping - I should be finished.

Is this doable? I was thinking that maybe this would avoid having to worry about nested group hidden grids and headers.



prl

#3
Quote from: Garry K on November 06, 2012, 10:43:16 PM
But this time set very specific rgb values to temporarily group things.

Yes, this will work.  I do this too. Just be careful about the "color by layer" setting.  In version 22, the infobox "color by layer" toggle overwrites the existing entity rgb values if the global "color by layer" setting is on and you examine the entity in the infobox and toggle the entity color by layer setting. This is a bug IMO.

Generally speaking, to store data with an entity,  I've found you can use individual component rgb values, or a data string (which you can parse for field data).  Sys$(300) or sys$(34) are the ones I use.  Note I use sys$(34) when I don't really care about the DesignCAD material.

Lar

Quote from: Garry K on November 06, 2012, 10:43:16 PM
Is this doable? I was thinking that maybe this would avoid having to worry about nested group hidden grids and headers.
You can turn off nested groups but you can't do anything about grid headers and lines if you are working with solids, unless you somehow explode the grids, which would turn them into a plane for every 'grid' of the grid surface.

Quote from: Garry K on November 06, 2012, 10:43:16 PM
... using >ApplyLayer ...
If you select the solids with points, ie, by >PointSelect, >DragSelect, or user interaction you can use >ApplyLayer. I just tested in 22 and it appears you can also use apply layer if you select the grid header with getattr and putattr, using the header's id number (and ignoring the grid lines).

However, I remember using get/putattr way back, before Query and Change (and maybe even >ApplyLayer) was available and I would have the problems with grids mentioned in my previous post. Maybe this was because I would've had to use sys(93) to change the layer, which would only change the layer of the grid header. Since then I always used the grid line method, so I can't say if there would be some problems with apply layer.

Lar



prl

Quote from: Lar on November 07, 2012, 08:15:13 AM
You can turn off nested groups

In version 22, technically I think this is incorrect.  If you toggle the "don't use nested groups", somehow the program merely ignores the type 34 entities.  They are still there and depending on your global setting for operating DesignCAD (use or don't use nested groups), you get different ways on how groups behave.  I have given up trying to sweep out the type 34 entities like I did in version 17.  Version 22 recreates all type 34 entities every time you use the infobox.  Like trying to sweep a sidewalk in a sandstorm.

Now I simply use nested groups and cycle the drawing database every so often and dump all type 34 entities on layer 1000 which I always keep ON.

prl

#6
Programmatically I often create assemblies off in deep space so I don't have any issue with the >pointselect command, say using a known x offset, say -500.  This way I am assured the pointselect command will only select the entity I created, not the one that shares an edge or corner with some other solid or entity.  Then using >sethandles and >move,  I move and rotate the assembly into the actual drawing position.  While it is still selected you could do the >apply layer.

Garry K

Everyone - Thanks for the information. I haven't actually used Query or Change - the Macro help file I have is for version 17. I have been using version 16 and 22 to test my macros. I am interested in a new help file if there is one.

Using Sys$(300) and or Sys$(34) seems like a really good idea. I must experiment. I have done a lot of off screen bit map work in C++  so I very much appreciate working in deep space.

I am appreciative learning about some of the more undocumented things like grids and headers. I'm thinking that experimenting a bit and then doing a data dump might reveal some of these more obscure things.

I am hearing that nested groups can lead into objects that may loose a bit of integrity. This is a good thing to keep in mind.

Again - thanks everyone.

prl

Quote from: Garry K on November 07, 2012, 04:35:32 PM
the Macro help file I have is for version 17. I have been using version 16 and 22 to test my macros. I am interested in a new help file if there is one.

Garry, as far as I know, the macros17.hlp and OLEDC17.hlp (both DC version 17) are the latest programmer's reference files.  Feel free to post questions, partial code snippets, etc.  Some long time users are here. 

prl

#9
Quote from: Garry K on November 07, 2012, 04:35:32 PM
I am appreciative learning about some of the more undocumented things like grids and headers. I'm thinking that experimenting a bit and then doing a data dump might reveal some of these more obscure things.

Grid headers and grid lines are standard DesignCAD entities and they work fine.  The shortcoming is the BasicCAD GetSelect statement which doesn't get all the entity ids of the selected items.  Specifically it leaves out the grid line ids.  I wrote a GetSelected.d3i subroutine which I use like a function that gets all the selected entity ids like it should. Below is a sample program called zzero.d3m which demonstrates how to use the GetSelected subroutine.  Feel free to use and alter as you need.

'Program: z0.d3m (zzero)
'make z data equal to zero - used to flatten a selection or whole drawing

include "dcadalias.d3i"

Sys(1027) = 4 'Yes/No MessageBox style
Message "WARNING!  This routine changes selected or ALL (if no selection) Z coordinates to ZERO. Do you wish to continue?"
if sys(1028) = 7 then 'No
    sys(80) = 0
    end
end if

if sys(80)=0 then
  >selecteverything
  {
  }
endif

gosub GetSelected 'loads the Selected() array and Nsel variable


zero = 0.000000000000000e+000
precision 15
for i = 1 to Nsel
  entity Selected(i)
  Query Ent_Npts, epoints
  for j = 1 to epoints
    Query Ent_Point, j, ptX, ptY, ptZ
    Change Ent_Point, j, ptX, ptY, zero
    Update
  next j
next i

regen
sys(1)=0
sys(1027) = 0
end


'subroutines follow
include "GetSelected.d3i"





'Subroutine getselected.d3m (get entities)

'takes selected items and creates a proper array list including grid headers and grid lines, the
'latter which are for some reason omitted when using the getselect i, entid statement

'Reserved variable names:  Selected(), Nsel, jsr, jjsr
'Currently set to a max of 20000 entities.

Getselected:
  if firstrun = 0 then
     dim Selected(20000)
     firstrun = -1
  endif
   
  Nsel = 0
  'get entity numbers of selection and store in array
  for jsr = 1 to sys(80)
    Nsel = Nsel + 1     
    getselect jsr, entindexnum
    entity entindexnum
    Selected(Nsel) = entindexnum
 
    if sys(90) = 32 then 'grid header, check for number of grid lines
       for jjsr = 1 to sys(99) 'grid line count
         Nsel = Nsel + 1
         Selected(Nsel) = entindexnum+jjsr
       next jjsr
    endif
   
  next jsr
  sys(1)=0
  sys(80)=0

Return


Lar

Quote from: Garry K on November 07, 2012, 04:35:32 PM
I am appreciative learning about some of the more undocumented things like grids and headers.
Just for the record grid headers and grid lines are documented, or at least they were when I learned about them back in the early 1990's.

Prl, in terms of using sys$(34), which is the default Material list folder, I would think that the named folder has to actually exist. Do you actually create or rename the folder before running the macro?

If I need data strings that don't have to be directly tied to an individual entity (in which case I use the entity name) I would name some of the layers that I never get to, or simply save text entities on a particular layer in the drawing. For global data that could be used in any file a line by line text file can be sequentially read with the open command.

I just thought about something: wonder if you can give different entity names to each grid line via a macro. That grid surface would be able to hold a bunch of data.

Lar

prl

#11
Quote from: Lar on November 08, 2012, 08:27:43 AM
Prl, in terms of using sys$(34), which is the default Material list folder

Thanks Lar, what I wrote is wrong.  Went back and checked. I use sys$(34) as a pipe to hold data when I have an OLE program run a BasicCAD program.  Similar to sys$(0).  For data that sticks with an entity (saving and reloading), sys$(300).  I corrected my original post discussing that.