Jump to content

Custom Line Type Tool by Class


Recommended Posts

Hello all, 

 

I'm hoping my explanation of this will make sense. I'm still having a hard time wrapping my head around Python. I'd like to create menu commands or even just a script palette where I can run a script and be able to immediately start drawing in a polyline that already has set class attributes. I've figured out how to set the polyline tool thanks to a code I found on the Vectorworks Developer website, but what I can't figure out is how to set those class attributes. Is this something that is even possible? Thanks in advance!

 

Here is the code I have been using:

 

 

def SetPolyline():
	vs.DSelectAll()
	
	def resultCallback1():
		h1 = vs.FSActLayer()
		vs.DSelectAll()
		
		def resultCallback2():
			h2 = vs.FSActLayer()
			h3 = vs.AddSurface(h1, h2)
			if h3 != None:
				vs.SetFPat(h3, 5)
				
					
		vs.SetTool(-204, resultCallback2)
		
	vs.SetTool(-204, resultCallback1)
		
SetPolyline()

 

Link to comment

Can we do this in Vectorscript instead of in Python?

 

The following script will temporarily (for the time it takes to draw one object) make the document attributes to be By Class, switch the active class to 'PTS' (edit to whatever you want), and activate the polygon tool.  Once you finish drawing the polygon it will revert to the previous tool and document attributes.

 

Procedure CustTool;
VAR 
Name:STRING;
Result:BOOLEAN;
BEGIN 
	PushAttrs;	{Saves the attribute settings so we can get them back after using the tool}


	FillColorByClass;	{These lines set attributes to By Class. More may be needed}
	FPatByClass;
	LSByClass;
	LWByClass;
	PenColorByClass;

	NameClass('PTS');	{set the class named PTS as active. Creates if it doesn't exist}

	CallTool(-207);	  {Makes the Polygon tool active}

	PopAttrs;	{Restores the attributes from before the command was run}
END;
Run(CustTool);

 

To make it change the settings so you can draw more than one polygon at a time, delete the PushAttrs and PopAttrs lines and change CallTool to SetTool.  The script will then change the attributes and just activate the Polygon tool.

 

If you want other attributes (Opacity, markers, etc.) to by ByClass you will need to add the appropriate additional lines above the NameClass. Search for ByClass in the Vectorsorscirpt function reference or ask again.

 

This thread has information about making a script into a Menu Command and adding that command to your workspace and giving it a keyboard shortcut.

 

https://forum.vectorworks.net/index.php?/topic/103512-saved-views/&do=findComment&comment=451792

 

Ask again if you need more help.

  • Like 1
Link to comment

Thank you so much, Pat!

 

So from what I understand, I need to set the class I want as the active class before running the script. Is there any way I might be able to also have the class active with the script? That way I wouldn't need to manually switch classes in the OIP.

Link to comment

Put the name of the class you want to be active for the tool in the NameClass line in single quotes in place of 'PTS'.

 

In the script above with the Push/PopAttrs (Effectively Save Attributes and Restore Attributes) the class in the script will only be used for the one object.  If you go to the version without Push/Pop then the class will be switched and you will have to change it manually or with another script if you don't want that class active any longer.

  • Like 1
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...