TMalus11 Posted December 11, 2020 Share Posted December 11, 2020 Hello everybody, I have created a tool command and call it up via an icon button. I have the problem that I first have to click in the drawing area before I can work with the actual command. What did I do wrong? Choose_Standard='Freudig_2' c= 'Bemaßung' tsize=10 import vs; def CustTool(): Result = vs.SetDefaultBeginningMarker(0, 15, 0.118103, 0.000000, 34, 0.050000, False); Result = vs.SetDefaultEndMarker(0, 15, 0.118103, 0.000000, 34, 0.050000, False); vs.PenSize(14); vs.PenBack(256); vs.PenFore(1271); Name = ''; if vs.Name2Index(Name) > 0: vs.PenPatN(-vs.Name2Index(Name)); CustTool(); Dim_Std = {} #Dictionary of Name and Index Number i=0;v='' while v !=1: try: vs.SetDimStd(i) except: pass vs.LinearDim((0,0), (0,0), 0, 0, 0, 0, 0) h=vs.LNewObj() v=vs.GetObjectVariableInt(h,0) #if 1 the function switched to 1 because of an error n=vs.GetObjectVariableString(h,27) vs.DelObject(h) i=i-1 if v !=1: Dim_Std[n] = v vs.NameClass(c); vs.SetDimStd (Dim_Std.get(Choose_Standard)); vs.SetPref(44,True); vs.SetTool(-211); vs.TextSize(tsize) Quote Link to comment
Vectorworks, Inc Employee klinzey Posted December 11, 2020 Vectorworks, Inc Employee Share Posted December 11, 2020 All tools require a click in the drawing, menu commands can be run without clicking in the drawing. Quote Link to comment
TMalus11 Posted December 11, 2020 Author Share Posted December 11, 2020 I mean that I have to click twice in the drawing. To be more precise, the tool is not executed until the second click. e.g. With the rectangle tool, I define the starting point with the first click. With my tool, nothing happens at the first click. Quote Link to comment
JBenghiat Posted December 11, 2020 Share Posted December 11, 2020 Your script calls SetTool(), so when you click in the drawing, then the script runs and sets the tool. The second click is the first click of the actual tool. Your options are either to run your command from a menu or tool palette, or rely on GetPt() etc and create the dimension via code rather than with it's tool. This is a limitation of VS-based tools. Quote Link to comment
TMalus11 Posted December 11, 2020 Author Share Posted December 11, 2020 Thanks for the brief analysis of my script, now I understand the matter a little better. I apologize for my questions, but I'm new to scripting and want to learn how to do it. So it would be better to program things properly right from the start. Can I solve this more easily with Python? What would such a program look like? Quote Link to comment
JBenghiat Posted December 11, 2020 Share Posted December 11, 2020 No apologies necessary. Vectorscript and Python are going to be the same in terms of functionality, though if you are new to scripting, using Python has the advantage of being a modern language with a lot of learning resources of anything outside the Vectorworks API, as opposed to Vectorcript, which is a proprietary version of PASCAL. Both, however, are run-time languages, so they depend on a singular trigger to run, in this case, clicking in the drawing. The solution depends on what you are trying to make easier and who your audience is. If these are just to automate your workflow, just move your code form a tool to a menu, and you're basically done. If you want something a little more user-oriented, you have to build your own tool. Your end result might be to run this command: https://developer.vectorworks.net/index.php/VS:LinearDim You can gather the end points with this: https://developer.vectorworks.net/index.php/VS:GetLine or this: https://developer.vectorworks.net/index.php/VS:GetPtL Find an example of collecting points in Python here: https://developer.vectorworks.net/index.php/VS:GetPt If you also want to set the distance from the object, you need to get a third point. You can associate objects with a dimension with this command: https://developer.vectorworks.net/index.php/VS:AssociateLinearDimension I can't recall if the tools will count the first click as the first point. You may need to use a TempTool to retrieve the first click: https://developer.vectorworks.net/index.php/VS:RunTempTool 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.