Jump to content
Developer Wiki and Function Reference Links Read more... ×
lucioing

How to set a NEW class

Recommended Posts

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 by lucioing

Share this post


Link to post

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?

 

Share this post


Link to post

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

Share this post


Link to post

You might want to consider reinstalling VW 2017. Your MyRect script runs fine for me under 2017 SP1 Beta. 

Share this post


Link to post

Ok, I'm getting crazy! 

New installation VW2017+SP1.

Nothing, it doesn't works.

Here's a screenshot

 

L.

 

MyRectPlug.gif

Share this post


Link to post

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.

 

 

PulginMngr.gif

Share this post


Link to post

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.

 

01.jpg

02.jpg

MyHandMadeRect_01.zip

Share this post


Link to post

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.

 

Share this post


Link to post
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.

Share this post


Link to post

Here's the code.

Thank you again! :D

 

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);

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×