Maarten DE Posted December 28, 2020 Share Posted December 28, 2020 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(); Quote Link to comment
Maarten DE Posted December 28, 2020 Author Share Posted December 28, 2020 I forget to mention, I tried the same with the gSDK->... functions too, same result, no symbol instance in the drawing. Quote Link to comment
Hippocode Posted December 28, 2020 Share Posted December 28, 2020 I believe when creating a symbol from the VWSymbolObj wrapper class it's not properly attached to a container, in your case the active layer. Try additing it manually after you create the symbol, and before you reset it using "gSDK->AddObjectToContainer" 1 Quote Link to comment
Maarten DE Posted December 28, 2020 Author Share Posted December 28, 2020 Hooray, that did the trick indeed 😄 . I got thrown off because in check 5, I did get the container info (the layer) so I assumed I didn't had to add it another time... Never a boring day with the SDK 🙂 . Thanks for the help! Quote Link to comment
JBenghiat Posted December 28, 2020 Share Posted December 28, 2020 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. Quote Link to comment
Maarten DE Posted December 29, 2020 Author Share Posted December 29, 2020 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 🙂 . Quote Link to comment
Recommended Posts
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.