Jump to content
Developer Wiki and Function Reference Links ×

Line Types in Plug-in Objects


michaelk

Recommended Posts

It's a little embarrassing, but I've never understood this:

 

When inserting a plug-in object in a blank document I want to use a line type.  SetLSN(0-72) uses a solid, nothing, or a pattern.  But what if I want an actual line style?

 

SetLSN(-#) works if there are already some line types in the document.  I'm guessing that the number is resource index number?

 

Questions:

 

1.  Is it possible (I don't see a way to do this) to script a custom line type?

 

2.  Can I check the VW defaults and import one of those line types if it's not in the drawing?  What happens if that line type already exists and has been edited by the user?

 

I'm sure this is a solved problem.  Just not solved or understood by me 🙂.  If anyone has some sample code or knowledge they can share I'd appreciate it!

 

Thanks!

 

 

Link to comment

Here is a code snippit from my "Draw Center Line" macro.  I think it will get you there.  Email me if you want to talk.

Most pertinent lines marked with a {************}

 

Sam

sjones@autoplotvw.com

 

 


CONST
    kDefautLineTypeNm         = 'ISO-08 Long Dashed Short Dashed';

 

 

        IF (GetObject(kDefautLineTypeNm) = NIL) THEN
            BEGIN
                ResList := BuildResourceList(96,14,'Attributes - Line Types',NumLineTypes);          {************}

                FOR Index := 1 TO NumLineTypes DO
                    BEGIN
                        LineTypeName := GetNameFromResourceList(ResList, Index);                        {************}
                                            
                        IF (LineTypeName = kDefautLineTypeNm) THEN
                            BEGIN
                                NeededLineType := ImportResourceToCurrentFile(ResList, Index);         {************}
                            END;
                    END;                    
            END ; {IF (GetObject(kDefautLineTypeNm) = NIL) }

Link to comment

Turns out you can script a simple line type.

 

GetDashStyleIndexN is pretty cool.  I don't know what the first boolean argument is for.  But True works.  The second argument is the number of pairs (from 1 to 5) that will follow.  Then one to five pairs of real numbers.

A simple dashed line will have one pair.  The first number of each pair is the length of the line segment.  The second is the gap following that line segment.

 

You can see the values when you edit a line segment.  ISO-11 Double-Dashed Dotted has 3 pairs.

image.thumb.png.7144d8c231a2a4616d938c4108973b9d.png

If the line type described in the function GetDashStyleIndexN exists in the drawing it will return the index number for it.  If it doesn't exist in the drawing it will create it and return the index number.

Then you can follow it up with SetDashLineTypeName to name it.

 

index := GetDashStyleIndexN(TRUE, 3, 
				0.12, 0.03, 
				0.11, 0.03, 
				0.12, 0.03);
boo := SetDashLineTypeName(index,kLineStyleName);
boo := SetParent(GetObject(kLineStyleName),GetObject(kStyleFolder));	

 

By making very slight and not perceptible variations from the line style I want, I can be assured that it probably doesn't exist as a default and create it from within the plug-in object.

 

 

 

 

  • Like 1
Link to comment

Here's how I get the Vectorworks default line styles into my plug-ins.  It's a little backward from what you would think, but it works.  Below is a line that would apply the 'ISO-02 Dashed' to the LNewObj.

 

SetLSN(LNewObj,-Name2Index('ISO-02 Dashed'));

 

This has been the only reliable way I've found to get the correct index for the Vectorworks default line types.  This is simpler than using a Resource List and importing in the line style.  The most important thing is remember to put the '-' in the call to get the default line type.

Link to comment

Correct.  The SetLSN procedure requires an index number to the line style, with "negative" values being the Vectorworks defaults.  But when they changed and expanded the Vectorworks defaults (back in 2014 or 2015), nailing down the index number got much, much more difficult.  The Name2Index function gives you the exact index based on the hard-coded name of the new defaults.  Feasibly in your situation, you would be able to use the same Name2Index call while passing in your unique named line style to get the index to it.  In that case, you wouldn't want to make it a negative value, so you could remove the '-' from the SetLSN call.

 

The downside in your case would be getting that line style into a drawing.  You could write the code to create it from scratch directly in the drawing, or you could have it in a supplemental file packaged with your plug-in, but then you would need to import it in using a combination of using FindFileInPluginFolder to get the path to the supplement and building a resource list with the process that Sam outlines above.

Link to comment

I'm just sticking a few lines in the plug-in object.  That way if the default line type is already in the drawing and used for other things and possible already edited, I don't have to worry about it.  This way gives me a line type that I can name that I'm positive no other object is using.

 

But I'm going to steal your method of bringing in default line types!

Link to comment

@Jesse Cogswell  What's the trick?  When I run the following script (including copy/paste your line from above) into a new blank document that does not have any resources, I end up with a line type of None.

 

Procedure Test;

BEGIN
    Rect(0,0, 4',4');
    SetLSN(LNewObj,-Name2Index('ISO-02 Dashed'));
End;

Run(Test);

Procedure Test;

BEGIN
	Rect(0,0, 4',4');
	SetLSN(LNewObj,-Name2Index('ISO-02 Dashed'));
End;

Run(Test);

 

 In the same file 

 

Message(Name2Index('ISO-02 Dashed'));

 

returns a Zero.

 

I have default content turned on and if I try to use the Attributes Palette to set a Line Type I get the default of ISO-02 Dashed imported into the file.

 

 

Link to comment

@Jesse Cogswell  What's the trick? I can't make this work in a new blank file with no resources.

 

Procedure Test;

BEGIN
	Rect(0,0, 4',4');
	SetLSN(LNewObj,-Name2Index('ISO-02 Dashed'));
End;

Run(Test);

 

Returns a line type of None.

 

Message(Name2Index('ISO-02 Dashed'));

 

In the same file returns a value of Zero. Which equates to the line style of None.

 

If I use the Attributes Palette to choose a Line Style then I get the 'ISO-02 Dashed' automatically imported. But the Name2Index does not work if the Name is not already a resource in the active file.

 

For me.

 

Tested in VW2023.

 

 

 

Link to comment

That's what I get for being in a hurry and not thoroughly going through my code.  I wrote a procedure in my plug-in to check whether 'ISO-02 Dashed' exists in the drawing and, if not, imports it in from the Vectorworks default using Resource Lists in the same manner that Sam posted above.  I had that procedure buried in the reset event with a IsNewCustomObject call, so missed it until I went more thoroughly through the code.  But you would still need the Name2Index call to accurately assign the line style with SetLSN, and that it needs to be a negative number.

 

Thank you @Pat Stanford for keeping me honest.  I remember having a really hard time trying to figure out how to get the index number, since older versions of the Function Reference had them listed in the appendix but it was eventually removed.  I eventually found it in the online Function Reference here (which does mention that it only works if the style is present).

 

Sorry to disappoint @michaelk , I thought I was being so clever.

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