Jump to content

Paolo

Member
  • Content Count

    103
  • Joined

  • Last visited

Community Reputation

42 Great

2 Followers

About Paolo

  • Rank
    Journeyman

Personal Information

  • Occupation
    Designer
  • Homepage
    https://fitplot.it/vwplugins/
  • Hobbies
    Vectorscript, Python, Objective C developer
  • Location
    Italy

Recent Profile Visitors

1,102 profile views
  1. I have found a way, it works, but has some inaccuracy (due to the PointAlongPoly precision), but I can leave with it. Of course, if there is a better solution it will welcome! import math def angleBetweenPoints(p1, p2): #given 2 point coordinates it retrieves the angle of the line passing between them orientation = None if p1[0]==p2[0]: if p1[1] <= p2[1]: orientation = 90 else: orientation = 270 if p1[1]==p2[1]: if p1[0] <= p2[0]: orientation = 0 else: orientation = 180 if (p1[0]!=p2[0]) and (p1[1]!=p2[1]): if p1[0]<p2[0]: quadrant = 0 else: quadrant = 180 orientation = quadrant+vs.Rad2Deg(vs.ArcTan((p1[1]-p2[1])/(p1[0]-p2[0]))) return orientation def tangentAtIndex(h, index, resolution): minDist = 1e308 #a very large number initially tangent = None ptVt, vertexType, arcRadius = vs.GetPolylineVertex(h, index) ht = vs.ConvertToPolygon(h, resolution) #cycle searching min distance for i in range(1, vs.GetVertNum(ht)+1): pi = vs.GetPolyPt(ht, i) dist = vs.Distance(ptVt[0], ptVt[1], pi[0], pi[1]) if dist < minDist: minDist = dist if (i > 1) and (i+1 < vs.GetVertNum(ht)): pt1 = vs.GetPolyPt(ht, i-1) pt3 = vs.GetPolyPt(ht, i+1) c = vs.ThreePtCenter(pt1, pi, pt3) tangent = angleBetweenPoints(c, pi)+90 else: if i == 1: #angle between 1 and 2 pt1 = vs.GetPolyPt(ht, 1) pt2 = vs.GetPolyPt(ht, 2) tangent = angleBetweenPoints(pt1, pt2) if i == vs.GetVertNum(ht): #angle between latest and latest-1 pt1 = vs.GetPolyPt(ht, vs.GetVertNum(ht)) pt2 = vs.GetPolyPt(ht, vs.GetVertNum(ht)-1) tangent = angleBetweenPoints(pt1, pt2) vs.DelObject(ht) return tangent #test a selected polyline h = vs.FSActLayer() for i in range(1, vs.GetVertNum(h)+1): t = tangentAtIndex(h, i, 512) p, vertexType, arcRadius = vs.GetPolylineVertex(h, i) vs.Locus(p[0], p[1]) vs.MoveTo(p[0]-1*math.cos(vs.Deg2Rad(t)), p[1]-1*math.sin(vs.Deg2Rad(t))) vs.LineTo(p[0]+1*math.cos(vs.Deg2Rad(t)), p[1]+1*math.sin(vs.Deg2Rad(t)))
  2. I am working on a script that converts Vectorworks polylines into SVG paths and I have managed to "translate" everything except for the cubic splines vertexes. I know that a cubic splines vertex control point is equivalent to two bezier vertexes, simply crossing the tangent lines, see figure. The problem is: how I determine the tangent exactly in a polyline vertex? The only way seems to go with this one… def vs.PointAlongPoly(h, dist): return (BOOLEAN, pt, tangent) …but I cannot know what distance the control point has. Furthermore, testing this (and the similar PointAlongPolyN), I get inaccurate results placing of the points on the curve. I know (from past experiences) that this function calculates distances on the poly just "polygonizing" the curve, but the conversion resolution is unknown (and not settable). Thank you for the help. Paolo
  3. Hello python experts, I am trying to install the Pillow module (on MacOS, Vectorworks 2021) using the function Marionette.VerifyOrGetLib() as from the following script: PIL = 'https://files.pythonhosted.org/packages/53/7d/c0db10e5f990905aa4bc4f8166414d8a30fb766c1624ced9fe9a43a211d9/Pillow-7.2.0-cp38-cp38-macosx_10_10_x86_64.whl' import Marionette if Marionette.VerifyOrGetLib('PIL', PIL): #vs.Message(PIL) from PIL import Image, ImageChops … This worked in Vectorworks 2020, now I am getting this annoying script error / warning: WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. Warning: You are using pip version 20.1.1; however, version 20.2.3 is available. You should consider upgrading … Though the library is correctly installed, is there a way to avoid this error / warning? I have examined the VerifyOrGetLib() function (on MacOS is inside /Applications/Vectorworks 2021 IT/Plug-in/Marionette.vwlibrary/Contents/Resources/Marionette.vwr/Scripts/Marionette.py) As far as I know (I am not a python expert), while on PC this function uses the Vectorworks pip installation, on MacOS, it seems to use the provided system pip that is different (hence the version warning). I do not know the old script wrapper warning means. @tbexon and @K.Lalkovski, any suggestion? Here's the relevant part of the function VerifyOrGetLib() : if sys.platform == 'win32': piploc = 'Python38\Scripts\pip3.exe' pathpip = 'Python38\Scripts' cdpath = os.path.join(appfolder, pathpip) cmdpip = os.path.join(appfolder, piploc) wd = os.getcwd() if os.path.exists(cmd) and os.path.exists(cmdpip): os.chdir(cdpath) ret_code = subprocess.call([cmdpip, 'install', missingLibURL, '-t', cmd ]) if ret_code > 0: vs.AlrtDialog('Module ', missingLib, ' cannot be downloaded.') exit_code = False else: exit_code = True sys.path.append(cmd + '\\') os.chdir(wd) vs.AlrtDialog('Module ', missingLib, ' has been successfully installed.') elif sys.platform == 'darwin': import pip import shlex pos1 = missingLibURL.rfind('/') pos2 = missingLibURL.rfind('whl') downloadedfile = missingLibURL[pos1+1:pos2] +'whl' destination = appuserfldr + downloadedfile command_line = "curl -o " + '\"' + destination + '\"' + " "+ missingLibURL args = shlex.split(command_line) ret_code = subprocess.call(args) if ret_code == 0: sys_executable_orig = sys.executable sys.executable = '/usr/bin/python' ret_code = pip.main(['install', destination,'-q','--target', cmd]) sys.executable = sys_executable_orig if ret_code > 0: vs.AlrtDialog('Module ', missingLib, ' cannot be installed.') exit_code = False else: vs.AlrtDialog('Module ', missingLib, ' has been successfully installed.') exit_code = True else: vs.AlrtDialog('Module ', missingLib, ' cannot be installed.') exit_code = False sys.path.append(cmd+'/')
  4. Thank you all. I think I am going to rewrite this python plugin in Vectorscript since all functions and procedures I need are in Vs. I know I should start to refactor my (Mouldings) plugins in python, but it’s a big work! Paolo
  5. Hello, Is it possible to use a VectorScript function in a python script? I have many procedures and functions (in an include .vss file) written in VectorScript and I would avoid to rewrite them all… There should be the vs.CallDynVSFunction for this, but how to use it? Someone has tried it? Are there examples? Thank you in advance Paolo
  6. Inspired by this post, I have added the full Paramount Wood Moulding catalog to my Mouldings Plugin. It taken just one day to convert all the downloaded dwg files to the proprietary cpf files (with the above mentioned tool Save Profile to File cpf). I did not found downloadable dwg archives for the Fox catalog, @AEChadwick could you give me a link?
  7. Thanks very much to Mr. @MullinRJ and Mr. @PatStanford, the case was been brilliantly solved! Here's the check passage to be sure a folder gets its unique name (paths is the string var to be queried): k := 1; {loop to check if there is already an object named paths or paths is the name of a plugin in the current workspace (conflict!)} {add '-1', '-2', …-'n' to paths until there is no more conflict match.} while ((getObject(paths) <> nil) or HasPlugin(paths, paletteName)) do begin if k = 1 then paths := concat(paths, '-', num2Str(0,k)) else {ho già aggiunto un numero} paths := concat(Copy(paths, 1, len(paths)-len(num2Str(0,k))), num2Str(0,k)); k := k+1; end; nameObject(paths); BeginFolderN(16); … EndFolder;
  8. Maybe this should work: FUNCTION HasPlugin( itemUniversalName :STRING; VAR PaletteName :STRING) : BOOLEAN;
  9. Ok, now that we found the cause, is there a procedure to get a list of the plugins names currently used so to check if a name can be used? The nameList() doesn’t show plugins names, just the objects named in the drawing. And what happens if I create a ‘Xyz’ folder, then, later, I install a ‘Xyz’ plugin? Just curious...
  10. Thank you @PatStanford and @MullinRJfor your help. Siding is actually the name of one plugin in my mouldings package. Is it not allowed to name an object with a name of a plugin? Tomorrow I’ll try with the word ‘Corner’ that is another plugin of the package. We will see... About restarting VW, I had the very same behavior on two different Vectorworks installations, home and office, both with the Mouldings Package installed, VW2020 SP4 Italian version.
  11. To verify @Pat Stanford conjecture, I have made this test: procedure test; var i : integer; h : handle; begin for i := 1 to nameNum do writeln(NameList(i)); h := GetObject('Siding'); if h = nil then {try to create an object and assign it the name 'Siding')} begin rect(0,0,100,100); setName(LNewObj, 'Siding'); {this gives an error!} end; end; run(test); Applied to a new empty document, the result (in the output file), the following: Nessuna Quote Irregolare Tavolozza-1 Script-1 No sign of any "Siding", though the last part of the script… setName(LNewObj, 'Siding'); Issues a script error (name already used!). Also manually naming an object (in the OIP) as 'Siding' is not allowed. Until now there is no a 100% chance that creating a symbol folder with a particular name will not lead to an error, despite all checks and control you can do priorly. "Siding" is a word not allowed, discovered by accident. How many more words like this are there? There is a list of the reserved words? I think I have to live with it!
  12. Hi Pat, the problem is that if you try GetObject('Siding'); it returns Nil, so you can think that 'Siding' is a name free to use, but… nameObject('Siding'); Returns a script error (name is already in use!). So I cannot be sure (AFAIK) if a name I pass to GetObject is really Nil because it either has nothing associated or is a "reserved" word like 'Siding'.
  13. In my Mouldings plugins package I use a file of symbols and symbol folders as a database to be used in the plugin. The database is browsable using a tree control like this. The symbol folders are created starting from an actual folder on the disk and, recursively, for each folder inside it. I use the following commands (inside the recursion cycle): {paths is the name of the actual folder as read from the disk} nameObject(paths); BeginFolderN(16); Unfortunately folders on the disk and symbol folders in Vectorworks do not behave the same. Vectorworks doesn't allow two entities with the same name. For example, two folders can have the same name on the disk as soon as they are in different locations. This cannot happen in Vectorworks, so I have a check to assign a progressive number each time a name already exists. {paths is the name of the actual folder as read from the disk} k := 1; while getObject(paths) <> nil do begin if k = 1 then paths := concat(paths, '-', num2Str(0,k)) else {I have already started the numbering…} paths := concat(Copy(paths, 1, len(paths)-len(num2Str(0,k))), num2Str(0,k)); k := k+1; end; nameObject(paths); BeginFolderN(16); In this way I will have, for example Folder, Folder-1, Folder-2 and so on. The problem is that I found a name ("Siding") that is probably a reserved word! In this case getObject('Siding') returns nil and nameObject('Siding') returns an error message saying that there is already an object with that name. Also Name2Index('Siding') returns 0 (no object associated with that name). This is a contradiction! Is there a way to see if a name is used other than to check for the associated object (that may fail!)? This is the test script if you want to verify the contradiction: procedure test; var h : handle; begin h := getObject('Siding'); if h = nil then message('No object with this name! ', Name2Index('Siding')); nameObject('Siding'); BeginFolderN(16); end; run(test); It shows a script error, here's mine (in Italian) It says that 'Siding' name is already existing, but how can I check in advance if a name exists, avoiding showing the script error? Thank you for the help.
  14. @tbexon, @K.Lalkovski, I know (from a beta tester) that the beta version 2021 bs still has the faulted version of pip3. Do you, @K.Lalkovski, know if this problem is going to be fixed or not?

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...