Jump to content
Developer Wiki and Function Reference Links ×

duplicate object from inside group to outside group.


michaelk

Recommended Posts

I'm trying to take the selected object inside a group (or other parent) and duplicate outside the group.

 

Seems simple.

 

Procedure WhyDoesntThisWork;

VAR	
	FantomObject:					HANDLE;
	CurrentLayer:					HANDLE;

BEGIN
	
			
			CurrentLayer := ActLayer;
			FantomObject := CreateDuplicateObject(FSActLayer,CurrentLayer);
                
END;

RUN(WhyDoesntThisWork);

 

The above script always duplicates the whole group.

 

What am I not understanding?

 

 

Thanks!

 

 

 

Link to comment

Even if you are inside a group when your run the command, the first selected object in the active layer is the group. 

 

If you know you are inside a group, you can iterate through the objects in the group to find the first selected, or use

the “Waldo” technique (see archives) to find the previous object to a newly created, temporary object. 

  • Like 2
Link to comment

FSActLayer literally does what it says, even though we may think of it as the selected object: only returns the first selected object of the active layer, no matter where you may be in the object tree.

 

The Waldo method is the best option for VS.  You can get the type of waldo’s parent to know if you are in a group (or group-like object, like annotations).  When you create an object, it’s selected, along with the previously selected objects, so PrevSObj(hWaldo) will give you the selected object in whatever container you may be in (layer, group, symbol definition, etc.).

 

If you know you’re in a group, you can use FInGroup, FIn3D, etc. to get the first object, and then loop through selected objects until you find the last one.

  • Like 1
Link to comment

Let's try and phrase this a little differently.  I am on a plane right now and don't have VW open, so please consider everything pseudo-code.

 

1.  As @JBenghiat says, FSActLayer does what it says and returns the First Selected Object on the Active Layer. Being inside a group or symbol or PIO does not effect the handle returned from this function.

 

2.  If you do If GetType(GetParent(MyObject))<>Layer, then you know that you are inside a group, symbol, PIO. You could also be in the Annotations Group or Crop Group of a viewport, or the Profile Group or Path Group of an extrude or extrude along path. Or probably inside a lot of other object types as well. You probably want to check the type of the GetParent handle to make sure you are in the type of object that you want.

 

3.  If you already have a handle to the group, you can use FInGroup to get the first object inside the group. You will then need to use NextObj or NextSObj to step through to find the object you are interested in. If you have another way (the Name of the object perhaps) you can select it directly without having to do the NextObj step.

 

4.  If you know you are in an object and that you have a single object selected, then the Waldo technique is probably required.  Create a new object, GetLNewObject, GetParent(Last New Object), If Parent=Group, then FInGroup, NextObj until Object=Selected. Delete Waldo, Duplicate SelectedObject, SetParent to Layer.

 

5. Or if you are editing manually, it might be easier to just use DoMenuTextByName to do the Duplicate and see if the duplicate happens to show up as the LNewObject then you could just to SetParent on that instead.

 

6. Tell us more about how you are selecting the object in the group and we might be able to offer better solutions.

 

 

  • Like 3
Link to comment

Thanks gentlemen.

 

I'm also on a plane, and my internet connection is very spotty.

 

Pat I'm trying to solve the Edit Class From Selected Object script that I forked from your script(without clearing out superfluous lines of code or even functions).

 

I've now stripped it down to what I thought would work and discovered that if the selected object was in a group (or VP annotation, etc.) the script produced very exiting and unexpected results.  That's when I discovered that the FSActLayer is just what Josh says.  

 

So my thinking was to try either

1.  duplicate the object to the active layer - outside any group, run the script, delete the object.

2. figure out a way to get to the handle of the actual selected object in the group.

 

Thanks for your help.  I now have a much better understanding of what is happening.  It seems that even if I still thought #1 was a good idea, I'd have to figure out #2 first!

 

I don't think this flight is going to be long enough for me to figure it out, but at least I have ideas for what to try next.

Link to comment

If you're just trying to get the class of the selected object, where's Waldo is probably going to be your best strategy here.  Duplicating the object doesn't really help you — it's getting a handle to the selected object that's tricky, not getting info about an object in a group.

 

17 hours ago, Pat Stanford said:

2.  If you do If GetType(GetParent(MyObject))<>Layer, then you know that you are inside a group, symbol, PIO. You could also be in the Annotations Group or Crop Group of a viewport, or the Profile Group or Path Group of an extrude or extrude along path. Or probably inside a lot of other object types as well. You probably want to check the type of the GetParent handle to make sure you are in the type of object that you want.

 

Just one thing to point out here: this is true once you get the handle to the selected object you want.  If MyObject = FSActLayer, by definition, the parent is always going to be a layer.

Link to comment

Thanks, Josh.

 

Yep.  I realize now that I don't need to duplicate the object.  I just thought that would be a workaround before learning that I didn't yet have the handle to the selected object.

 

Looks like I need to figure out how to get the handle no matter what the parent object is.

Link to comment

Selection status is actually like a flag that saves with the object, so selection maintains even if an object isn't selected and editable.  You may notice that objects on inactive layers stay selected when you switch back to the layer (if you haven't done a DSelectAll).  Running the criteria will give you ALL selected objects.

 

This should work:

Locus(0,0);
waldo = LNewObj;
hSelected = PrevSObj(waldo);
IF (waldo <> nil) THEN
	DelObject(waldo);

 

Link to comment

Another possibility:

 

If you put the interactive select object into the script, you could put a DSelectAll at the beginning of the script so you will know you don't have anything selected.

 

Select the object and then use FSObject to get a handle to that object. Probably want to check the NumSelectedObjects first to make sure that you only have a single object selected.

 

I think this will work even if you are in a group or symbol.

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...