Jump to content

floring

Member
  • Posts

    6
  • Joined

  • Last visited

Everything posted by floring

  1. Can I ask where are these coming from: vs.PLength, vs.PHeight, vs.PExtrusion? "vs" namespace does not seem to have them? See https://developer.vectorworks.net/index.php/VS:Function_Reference If I try to run the script above, I'm getting, AttributeError: vs module does not have attribute PLength.
  2. 2023 Max 2 Pro with 96 GB RAM. It does good.
  3. Thank you for the reply! Any tip is greatly appreciated. GetMouse() is not accurate for my application. I think I understand what PenLoc() is meant for therefore it won't work. I scrapped this script and changed the approach. What I was looking for was reference lines to aid with creation of new items. With a shortcut. Next day I found the Guides under the Modify menu. Awesome. So I tried a new script, that would take a simple line positioned with precision and direction, and assigned it to Guides class, achieving my goal precisely. ChatGPT is atrocious with Vectorworks, yet it worked well with Python. Again, any correction is welcome. What is "Marionette Maven"? import vs import math # @florin, 09/12/2023 # find the page dimensions current_layer = vs.ActLayer() page_width, page_height = vs.TBB_GetPageArea(current_layer) pw = page_width * 24.5 # translate to mm ph = page_height * 24.5 # translate to mm # remember existing active class, go back to it when done with the construction line active_class = vs.ActiveClass() counter = 0 # not used message = "" # not used # per chatgpt, find angle between two points # where each point has an x/y coordinates set # these x/y coordinates are given by vw, via vs.GetSegPt1, vs.GetSegPt2 def find_angle(p1, p2): x1, y1 = p1 x2, y2 = p2 radians = math.atan2(y2 - y1, x2 - x1) return math.degrees(radians) # per chatgpt, project next x/y location given angle and distance # distance is calculated using page dimensions def project_point(x1, y1, angle_degrees, distance): # Convert angle from degrees to radians angle_radians = math.radians(angle_degrees) # Calculate the new x and y coordinates x2 = x1 + distance * math.cos(angle_radians) y2 = y1 + distance * math.sin(angle_radians) return x2, y2 def class_change_callback(obj): type = vs.GetTypeN(obj) global counter global message #types = types + ",{}".format(type) counter += 1 if type == 2: # 2 is type for line # get starting and ending coordinates cx, cy = vs.GetSegPt1(obj) dx, dy = vs.GetSegPt2(obj) # angles go in opposite directions angle1 = find_angle((cx,cy),(dx,dy)) angle2 = find_angle((dx,dy),(cx,cy)) #message = "{},{}".format(angle1,angle2) # start x,y and end x,y of the line sx, sy = project_point(cx, cy, angle1, (pw*ph)/2) ex, ey = project_point(dx, dy, angle2, (pw*ph)/2) vs.SetSegPt1(obj, sx, sy) # set next x/y in oner direction vs.SetSegPt2(obj, ex, ey) # set next x/y in oposite direction red = vs.RGBToColorIndex(65535, 0, 0) # red color vs.SetPenFore(obj, red) # set color of line vs.SetLW(obj, 1) # line weight vs.SetClass(obj, "Guides") vs.DoMenuTextByName("Lock",0) vs.SetDSelect(obj) # deselect the line # Iterate through all objects in the document and apply the callback function # vs.ForEachObject(class_change_callback, "INSYMBOL & INOBJECT & INVIEWPORT & (VSEL=TRUE)") vs.ForEachObjectInLayer(class_change_callback, 3, 0, 4); #{ Visible/Selected objects, Shallow, Editable Layers } #vs.Message("{}".format(message)) # revert to originally active class vs.NameClass(active_class) vs.SetTool(-240) # ensure Selection tool is active
  4. Thanks! Using another editor will still result in cut and paste I guess. Is there a way to link an external editor? Not mixing tabs and spaces remains the only option.
  5. *newbie alert*don't know python*new to Vectorworks* If anyone can critique / improve this script, much obliged. The script is drawing a line. The following are the issues: 1. How to use PenLoc() correctly; now it is always returning 0.0, 0.0 (the center of the page) 2. How to tell a newly created class to "Use at Creation" 3. How to tell the plugin script editor to use spaces when tab is pressed? Strange beast this python is. Finally, anything else I do wrong, anything I could do better. Thanks y'all. import vs # Get the current cursor position # I'd really like to use vs.PenLoc() cx, cy = vs.GetMouse() # delect all items to avoid conflicts in the creation of this construction line vs.DSelectAll() # remember existing active class, go back to it when done with the construction line active_class = vs.ActiveClass() # Get the page width (it comes in inches) current_layer = vs.ActLayer() page_width, page_height = vs.TBB_GetPageArea(current_layer) pw = page_width * 24.5 # translate to mm ph = page_height * 24.5 # translate to mm # start x,y and end x,y of the line sx = -pw sy = cy ex = pw ey = cy # vs.Message("cx: {}\ncy: {}\npw: {}\nph: {}".format(cx, cy, pw, ph)) # create the line vs.Poly(sx,sy,ex,ey) # decorate the line, by creating a new class def class_change_callback(obj): # make sure line is not left selected vs.SetDSelect(obj) # line to be controlled by class vs.SetPenColorByClass(obj) class_name = "Ref Line" vs.NameClass(class_name) # create a new object # set color to class red = vs.RGBToColorIndex(65535, 0, 0) # vs.SetClPenFore(class_name, red) vs.SetClass(obj, class_name) # redundant: set line weight and color to object as I don't know how to 'Use at Creation' and let class control object vs.SetLW(obj, 1) vs.SetPenFore(obj, red) # revert to originally active class vs.NameClass(active_class) # Iterate through all objects in the document and apply the callback function vs.ForEachObject(class_change_callback, "INSYMBOL & INOBJECT & INVIEWPORT & (VSEL=TRUE)")
×
×
  • Create New...