Jump to content
Developer Wiki and Function Reference Links ×

Make Object Child of PIO


Fuge

Recommended Posts

Curious if someone can confirm what I'm seeing with the following script.     Below.. I'm wanting to select an object and make it a child of a PIO.     It appear from the testing I've done that the PIO has to already exist, or exist on the layer, before it can be made the parent.   It appears the PIO can't created during the script,  and isn't realized yet...  for CreateDuplicateObject to work.   If the PIO already exists on the layer and selected with the other object to be made the child,  CreateDuplicate works fine.. 

 

Maybe I'm missing something...  but I'm wondering how I can make this work if the PIO isn't already on the layer prior to running the script.  What's a workaround or another approach?  Should the PIO be made a symbol..  Would making it into a symbol, and inserting the symbol during run behave different since I wouldn't be "creating" it since it would already exist?!

 

Thanks!!

 

PROCEDURE SetParent;

VAR


  h1, h2, hPIO, DupObjh: HANDLE;
  ObjName :STRING;

 

BEGIN

 

  {   Select an object, run, script adds the PIO, Does not work 😞  }

  ObjName:= 'TESTPIO'; 

  h1 := FSActLayer;
  hPIO := CreateCustomObject( ObjName ,0,0,0) ;
  SetSelect( hPIO );
  DupObjh := CreateDuplicateObject( hPIO, h1 );

 

 

{  Sub this...   On the active layer, select an object, then select the PIO, run, works   }
{
  h1 := FSActLayer;
 h2 := NextSObj(h1);
 DupObjh := CreateDuplicateObject(h2, h1);
}

END;
RUN(SetParent);

Link to comment
  • Vectorworks, Inc Employee

What you are trying to do will not really work because of the nature of a PIO.
When a PIO is reset the PIO starts as an empty container and redraws everything, so when you put an object in the PIO container it will exist but will deleted when the PIO receives a reset event.

In order to do want you want you will need to add the selected geometry to the Profile Group of the PIO and then have the PIO copy the geometry from the Profile Group into the main PIO during the reset when the main PIO code is run.

Link to comment

Whether this helps or not.

One of my plugins for drawing pickets in a fence could not create itself by collecting three points interactively from the user.

It will edit itself if any existing defining points are moved. This is done through reassignment of the values stored in the instance's record.

But because the object didn't yet exist during creation until after the object script completed the record I was attempting to place values into didn't yet exist.

 

This was solved by creating a tool to place the first instance. The tool collects the three initial defining points from the user, executes the plugin and then replaces the values in the instance's record.

By using a tool the plugin object created is free to run by its own script and not contained as an object within the creation script.

Link to comment

Yes you definitely have a few conceptual challenges.

You can create a Tool plugin that could capture the user's selection and create an object plugin. But passing a handle into a record's field attached to the plugin would not work for a permeant instance of a plugin because handles are temporary in nature.  Object plugins being creation scripts would need to know how to recreate the user's selection or where to find a premade definition in order to display it. Objects the user creates are simply stored sequentially as a series of hidden commands written in a layer's definition. You would need to name an object with a unique name to reliably find it again and there is no guarantee it was not deleted or manipulated in some way. Capturing the user selected object and stashing it or copying it into a symbol definition created by a Tool plugin would be probably the easiest start. A symbol's name can be stored in a field of an Object's attached record for retrieval by the script of the object plugin.

You can think of a Layers, symbols and groups as containers, each with their own strengths and weaknesses, all three are parents to basic object creation commands.

Link to comment

If you are really trying to link objects best to use a UUID.  There is a VS Function to generate. The problem is that ONLY field in VW that forces uniqueness is the Name field visible in the OIP. However, in a quick glance at the Function Reference, there is now a GetObjectUUID function and a GetObjectByUUID function.  I have not tested, but it appears that you could Get an objects UUID, store that in a record and the use that to find the "linked" object again.

 

After a quick test, the GetObjectUUID does return different values for duplicated objects, so the above may actually work to link objects.

 

 

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...