Jump to content
Developer Wiki and Function Reference Links ×

Placing a symbol instance on a layer


Maarten DE

Recommended Posts

Hi all

 

I want to create a symbol definition and place an instance of it in the drawing (active layer).

 

I'm probably missing the obvious here, but why doesn't this work:

 

	// 1. Create the symbol definition, add a line to it.
	TXString symName = "a unique symbol name";
	VWSymbolDefObj symDef = gSDK->CreateSymbolDefinition(symName);
	symDef.AddObject(gSDK->CreateLine(WorldPt(0, 0), WorldPt(100, 100)));

	// 2. Reset to make the line visible in the symbol definition.
	symDef.ResetObject();

	// 3. Refresh Res Browser to make symbol def visible.
	gSDK->RefreshResourceBrowserResourcesList(true);

	// 4. Place this symbol on the active layer (reset all just to be sure)
	VWSymbolObj symInst(symDef, WorldPt(0,0), 0);
	symInst.ResetObject();
	symInst.SetVisible(true);
	symInst.ResetObjectsVisibility();

	// 5. as a check: get the name of the layer the object is placed on.
	MCObjectHandle* pOutContainerHandle = new MCObjectHandle;
	short* pOutContainerType = new short;
	double* pOutContainerScale = new double;
	symInst.GetContainerInfo(pOutContainerHandle, pOutContainerType, pOutContainerScale);
	VWLayerObj lay(*pOutContainerHandle);
	TXString layName = lay.GetName();

	// The name of the layer is correct, but the symbol is not visible/selectable on the active layer.

Step 1, 2, 3 works fine, the symbol definition is created and visible in the Resource Browser. I can manually drag and drop it in the drawing.

 

Step 4 and 5 seems to work too, I get the container info (the active layer) but still, I don't see the symbol in the drawing.

 

Oh, and I'm doing this in CMenu_EventSink::DoInterface();

 

Link to comment

I'll also use InsertBefore/InsertAfter. I believe this is also necessary with parametric objects and groups, at least when creating via the object construction.

 

I believe that these objects add to the document tree after the termination node, so even though the parent is correct, they are not actually in the visible document list.

 

As a side note, I believe that instead of creating new pointers, you can simply create a variable instance and pass the address. i.e. 

MCObjectHandle hOutObject = nullptr;

...

symInst.GetContainerInfo( &hOutObject...

That lets your memory be managed by the scope, which is a bit simpler.

Link to comment

I'm using gSDK->AddObjectToContainer() now and it seems to work fine. But I'll keep that InsertBefore/InsertAfter in mind whenever something strange pops up on the way, thanks for the tip!

 

And you're right about the nullptr, the function will already create a new instance. I've been out of the whole computer/programming/Vectorworks world for several years so it's all a bit rusty, but it's slowly coming back 🙂 .

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