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.

Group Denester (modified from original post)

Started by bdeck, January 05, 2009, 07:24:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bdeck

Below is a macro that converts all nested groups to simple, one-level groups, in either the present file or a copy saved to disk.

It also allows the user to choose whether to leave baselevel group entities intact, or delete them.

The option is because the problem with this macro and with the KillGroupEntity macro (in the user contributions section) is that after Type 34 group entities are erased, the remaining groups can no longer be succesfully manipulated with the groupdefine command.

My prior version reinstalled group entities by cutting and pasting the entire drawing to itself, using the following subroutine:

fixup:                  ' used to force DC to reassign Group entities where there are none

   >SelectAll     
   {
   }
   hx=sys(190)
   hy=sys(191)
   hz=sys(202)
   >Cut
   {
   }
   >paste
   {
   <type 1
   <pointxyz [hx,hy,hz]
   }
   >deselect
   {
   }
return

This worked fine in both version 17 and 18, but was probably overkill in v 18.

Also, this version saves from a "New" window, forcing the >save command to always display the fileselector dialog, emulating a saveas fileselector which is oddly unavailable in DC.

BD

PS: this is a convoluted way to de-nest groups in drawing, but every simple, normal, obvious method I tried failed, apparently because of DC's internal housekeeping.


Edited version 1/6/09

''gdn02.d3m        group de-nester    bd    01/09

' converts nested groups to simple groups
' then deletes the group entities

Alias ENT_POINT  &H010E 
Alias ENT_SELECTED  &H010C 
Alias ENT_TYPE  &H0101

dim ent(500)

do while (r1$<>"1" and r1$<>"2" and r1$<>"0")
a$=" 0 = Exit,   1 = De-Nest groups in this file,   2 = Save a De-Nested Copy"
input [a$],  r1$
loop

if r1$="0" then end

if r1$="2" then
gosub copier
else
if r1$="1" then
gosub main
gosub killquery
endif
endif

end
'_____________________________________ begin subs

main:
gosub pushback  ' Critcal: do this first so that groupxplode doesn't muck up entity list

gosub getgmax  ' get current inventory of all groups

for i=1 to emax
    getattr i,type,sel,grp   
    if grp>0 and grp <= gmax then gosub denest
next i
return

killquery:
Sys(1027) = 4 'Yes/No MessageBox style
Message " Leave bottom level Type 34 group entities intact ?", chr$(13), chr$(13),"BEWARE of strange behavior if not left intact. !"
If Sys(1028) <> 6 Then
gosub killgroupentities
End If
return

copier:
sys(36)=2  ' silent mode
>Selecteverything    'Use select all if you dont want to save locked layers. (Note invisible layers will be lost)
{
}
hx=sys(190)
hy=sys(191)
hz=sys(202)
>Copy
{
}
>new    'open a temporary workspace
{
}
>paste    ' paste the prior drawing in
{
<type 1
<pointxyz [hx,hy,hz]
}

gosub main
gosub killquery
'gosub killgroupentities   'optional replacement for prior line if no query is desired

>save
{
<filename "*.dc2"         ' this parameter does nothing without a complete filename
}

>Close    ' close the temporary drawing
{
<SaveChanges 0
}

sys(36)=0

>deselect
{
}
>redraw
{
}

return



denest:         'repackage nested groups into a single level

entity i
query ent_point 1, x,y,z

>pointselect
{
    <Type 0            'xor select
    <pointxyz [x,y,z]
}

gcount=0
for j=1 to emax
getattr j,t,sel,g
        if sel mod 2 then
if g>0 then
ent(j)=1
gcount=1+gcount
endif
endif
next

if gcount>1 then
>recursivegroupexplode
{
}
endif

for j=1 to emax
if ent(j) then
entity j
change ent_selected, 1
update
ent(j)=0     
endif
next
if gcount>1 then
        >groupdefine
{
}
endif
>deselect
{
}

return

pushback:     'move all group entities to the back of the list
>deselect
  {
}

for i=1 to sys(9) 
getattr i,t
if t<>34 then   
putattr i,t,1   'select all nongroups
endif

next i
>movetoback ' move them to BOTTOM of list
{
}

>deselect
{
}


return

getgmax:   
for i=1 to sys(9) 
getattr i,t
if t=34 then exit for
next i
gmin=i
emax=gmin-1
         
gmax=0
for i=gmin to sys(9)
getattr i,t,s,g
if g>gmax then gmax=g
next i
return

killgroupentities:
             count=0
            sys(80)=0
For i = 1 to Sys(9)
  Entity i
  If Sys(90) = 34 Then
    PutAttr i, 34, 1
    count = count + 1
  End If
Next i
If count > 0 Then
  >Erase
  {
  }
End If
return






prl

Hi Bd, happy 2009 to you.  I'll have to study your code but up to now I have been simply using k34.d3m to de-nest (or is it un-nest) drawings.  Also you will get a kick out of one of the new features in version 19 (hint - classic coke vs new coke).

bdeck

#2
Hi prl,

Do you have a link to k34.d3m?

Keyword search finds nothing.

Thanks, and have a great year.

BD


PS: Classic Coke sounds pretty good right about now.

In the meantime, I modified the file above to be a bit friendlier.

prl

bdeck, not sure where it is although I'm sure it is listed somewhere.  Easy enough, here it is:

'k34.d3m
' Finds entities of type 34 and deletes them

Sys(80) = 0
For i = sys(9) to 1 Step -1
  Entity i
  if Sys(90) = 34 Then
    PutAttr i, 34, 1
    count = count + 1
  End If
Next i

If count > 0 Then
  >Erase
  {
  }
End If

sys(1) = 0
Message count, "Type 34 Group entities found and deleted."
End

bdeck

#4
Hi Prl,

Thanks.

K34 is in my macro as the subroutine "KillGroupEntities" from the DT macro of the same name (December 2006).

K34 has 2 problems:

1) Used alone, it ungroups things that need to stay grouped.
2) After it is run, grouped items cannot be incorporated into a new group, unless measures are taken to force DC to reassign them to a new group entity.

This macro (gdn02.d3m) keeps all groups together, but eliminates the intermediate nesting. Killing entity 34 is optional.

Unnested groups are much easier to navigate in basiccad, and they don't break old software, as in Bill Snell's case with his old cnc converter.

BD 




prl

Thanks Bd.  Your code is more elaborate than I expected.  For me, k34.d3m only eliminates the nested tag (entity 34), keeps all basic groups as groups and I can always redefine new simple groups without problems.  Keep in mind I execute k34.d3m after each group define but even if I group some simple groups, things still seem to work for me. I'm sure you have actually thought this through way more than I have, but in the end I decided I only wanted classic groups anyway since the other way creates the container entity which changes the behavior of groups completely.

bdeck

#6
Quote from: prl on January 06, 2009, 03:33:41 PM
I execute k34.d3m after each group define

Hi prl,

Wow, if that works in your versions, then I really need some of that classic coke.

On my versions (17.2, 18.2) once k34 is run, any entities that have been stripped of their containers must be ungrouped before they can be used in another group. (Version 18.2 figures this out for itself, but requires some failed manual operation to intitiate the process. Then it simply creates new  containers. Neither 17 nor 18 will work without the containers in place.)

To see whats happening,

1) Create a group made up of other groups.
2) save the file as dc2
3) Run k34.
4) Save the file again as dc2 with a different name.
5) compare the listings of the two files.

On versions 17.2 and 18.2, you'll notice that k34 strips the container entities, but leaves multiple group designations among the entites, even though they behave as a single group. That can't be good.

By magic, genius, or dumb luck, DC manages to display the group without causing my PC to burst into flames.

At any rate the improper group designations are bound to cause problems sooner or later.

It sounds as though the new version of DC handles these issues much better.  Hope it gets here soon.


BD


PS. In the meantime a better name for this macro would be "classic converter." It takes nested groups and converts them to classic groups.




prl

bdeck,  in an effort to fix problems, IMSI made the problem worse in version 18.  The behavior of groups including nested groups is different in 17.2 and 18.2.  k34.d3m works in version 17, but needs to be executed twice in a row for version 18.  Needless to say, version 18 is so screwed up in my opinion, it is ranks up there with version 16. 

Dempsey

As someone mentioned earlier, only the odd versions (15, 17, 19) are acceptable. Oops, V19.0 is not officially released yet, so let's hope that it stays good after our beta testing...
Dempsey