lucioing Posted October 14, 2016 Share Posted October 14, 2016 (edited) Hello! I'm unable to set the proper class to a new obj. What's wrong with this? In my opinion, it a very, very simple script, but what I get is not what I need: create a closed parametric polygon (ok) to a class... Thank you L. VW 2017 SP1 Here's the script. PROCEDURE Poly_1; CONST {capitalized to distinguish them from variables} NOTHING=''; VAR s:STRING; i:INTEGER; layerHandle, objectHandle:handle; BEGIN PenSize(14); PenPat(2); FillPat(1); PenFore(0,0,0); PenBack(65535,65535,65535); FillFore(0,0,0); FillBack(52000,52000,52000); NameClass('MyObj'); ClosePoly; BeginPoly; Poly( 0,0, 0,pH1+pH2, pL1,pH1+pH2, pL1,pH1, pL1+pL2,pH1, pL1+pL2,0 ); EndPoly; {objectHandle := LNewObj; <-------- I've tried this way but it doesn't works too SetClass(objectHandle, 'MyObj');} END; Run(Poly_1); Edited October 14, 2016 by lucioing Quote Link to comment
Pat Stanford Posted October 14, 2016 Share Posted October 14, 2016 It works for me. I added constants for PH1, PH2, PL1, PL2. When I run the script for the first time it creates a class named MyObj, makes that the active class and creates the new object in that class. What are you seeing? Quote Link to comment
lucioing Posted October 14, 2016 Author Share Posted October 14, 2016 I think it doesn't works on 2017 SP1, because this simple code runs under 2015 but doesn't under 2017 SP1 Procedure MyRect; VAR a:real; BEGIN NameClass('MyClass'); rect(0,0,100,100) END; RUN (MyRect); So, I'm unable to understand why! Anyway, Pat, thank you for your reply. Lucio Quote Link to comment
Pat Stanford Posted October 14, 2016 Share Posted October 14, 2016 You might want to consider reinstalling VW 2017. Your MyRect script runs fine for me under 2017 SP1 Beta. Quote Link to comment
lucioing Posted October 14, 2016 Author Share Posted October 14, 2016 OK. I'll try! Thank you again, Pat! See you soon L. Quote Link to comment
lucioing Posted October 15, 2016 Author Share Posted October 15, 2016 Ok, I'm getting crazy! New installation VW2017+SP1. Nothing, it doesn't works. Here's a screenshot L. Quote Link to comment
lucioing Posted October 15, 2016 Author Share Posted October 15, 2016 Ok, got it! It depends on the 'type' of plugin. Here's a picture. It seems that 'point obj' doesn't works correctly, as shown... L. Quote Link to comment
lucioing Posted October 15, 2016 Author Share Posted October 15, 2016 I've tryied an old plugin I wrote some years ago... If I define it as 'Point tool', it doesn't works. I've also export an object created straight in VW (2017) and it is the same! Please, let me know about... L. MyHandMadeRect_01.zip Quote Link to comment
Pat Stanford Posted October 17, 2016 Share Posted October 17, 2016 So in a PIO the class MyClass is being created, but the object is not being assigned to that class. The Rectangle inside the "container object" that is the PIO is assigned to MyClass, but the PIO instance is not. Ungroup the PIO to see the rectangle and the class. Everything that happens inside the PIO is basically hidden from the rest of the drawing functions. It kind of runs in its own special space and then the result is drawn in the correct place in the VWX drawing. Since you are changing the class inside the PIO routine, this class change only effect objects drawn inside the PIO and not the PIO container or the active class after the conclusion of the PIO regeneration. I can't think of a work around right now, but I will sleep on it and see what I can come up with. Quote Link to comment
JBenghiat Posted October 17, 2016 Share Posted October 17, 2016 The quick version: Use GetCustomObjectInfo() to get a handle to the currently executing PIO. http://developer.vectorworks.net/index.php/VS:GetCustomObjectInfo Use SetClass() to set the class of the PIO itself. Note, the PIO will always be in this class. Setting the PIO's class on first insertion is possible but a little more complex. HTH, Josh Quote Link to comment
Pat Stanford Posted October 17, 2016 Share Posted October 17, 2016 Thanks Josh. I knew there was a way, but I could not pull it up yesterday. Quote Link to comment
lucioing Posted October 17, 2016 Author Share Posted October 17, 2016 52 minutes ago, JBenghiat said: The quick version: Use GetCustomObjectInfo() to get a handle to the currently executing PIO. http://developer.vectorworks.net/index.php/VS:GetCustomObjectInfo Use SetClass() to set the class of the PIO itself. Note, the PIO will always be in this class. Setting the PIO's class on first insertion is possible but a little more complex. HTH, Josh Great jbenghiat! I never though to this! Thank you so much! L. Quote Link to comment
lucioing Posted October 17, 2016 Author Share Posted October 17, 2016 Here's the code. Thank you again! L. Procedure MyRect; Var a:real; objectName : STRING; objectHand, recordHand, wallHand : HANDLE; b: BOOLEAN; Begin NameClass('MyClass'); Rect(0,0,100,100); b:=GetCustomObjectInfo(objectName,objectHand, recordHand, wallHand); SetClass(objectHand, 'MyObj'); End; Run (MyRect); Quote Link to comment
JBenghiat Posted October 18, 2016 Share Posted October 18, 2016 One thing to note here, using NameClass() also sets the active document class to 'MyClass'. You have two ways around that: 1. Use ActiveClass() to set a variable to the current class and then use NameClass( savedClass ) at the end of the script to restore. 2. Use PushAttrs / PopAttrs to save and then restore current settings. -Josh Quote Link to comment
Pat Stanford Posted October 18, 2016 Share Posted October 18, 2016 NameClass does not seem to set the overall active class in the document when it is used inside a PIO. It does change the class in the PIO and all the objects that are created after NameClass in the PIO are set to that class, but the PIO itself is placed in the class that was active when the PIO was created and the Active Class in the document remains unchanged. 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.