Jump to content
Developer Wiki and Function Reference Links ×

How to set a NEW class


lucioing

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
Link to comment

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

Link to comment

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.

 

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

Link to comment

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

Link to comment

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

Link to comment

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.

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