S. Robinson Posted January 12, 2014 Share Posted January 12, 2014 Can someone more experienced than myself explain what is happening here? Open the attached vwx file and run the included script from the script palette -or- paste the Python code below into a script in your own document and run it from the script palette. It does the following: Set the origin to 0,0 and place objects at 9 points in a grid surrounding that. Set the origin to 1,1 and do the same. However, rather than seeing the points shifted to x +1, y +1 and being centered around that, every point shifts outward from the document origin by 1,1. Regardless of positive or negative value, the point moves away from the document origin. Continue with 2,2 through 5,5 and you'll see the "burst pattern" this creates. I've read everything I can find on the multitude of issues associated with user origin (specifically http://www.vectorlab.info/index.php?title=Absolute_Origin), but this seems like a bug. Additionally, vs.ScreenPtToModelPt2D() and its siblings seem to be suffering from this same malady. Or am I simply implementing all of this incorrectly? import vs def makePoints(i) : vs.SetOriginAbsolute(i,i) makeText([-1,1], i) makeText([0,1], i) makeText([1,1], i) makeText([-1,0], i) makeText([0,0], i) makeText([1,0], i) makeText([-1,-1], i) makeText([0,-1], i) makeText([1,-1], i) def makeText(pt, i) : vs.MoveTo(pt[0], pt[1]) vs.CreateText(vs.Concat("origin:", vs.Num2Str(1,i), ",", vs.Num2Str(1,i), chr(13), "X:", vs.Num2Str(1,pt[0]), " Y:", vs.Num2Str(1,pt[1]))) origin = vs.GetOrigin() vs.PushAttrs() vs.TextFont(vs.GetFontID('Arial')) vs.TextJust(2) vs.TextVerticalAlign(3) vs.FillPat(0) vs.Opacity(100) vs.PenSize(5) vs.PenPat(1) vs.PenFore(vs.RGBToColorIndex(1,1,1)) vs.PenBack(vs.RGBToColorIndex(1,1,1)) vs.TextSize(6) points = [0, 1, 2, 3, 4, 5] for i in points : makePoints(i) vs.SetOriginAbsolute(origin[0], origin[1]) vs.PopAttrs() vs.SetZoom(50) Quote Link to comment
Miguel Barrera Posted January 15, 2014 Share Posted January 15, 2014 I never change the origin for the same problems that you are having. Rather than changing the origin, change the center location for each group iteration. What I also see in the code is that it is missing the text origin. Instead of MoveTo, which only moves the mouse to that location, use TextOrigin to set the location of the text center (justification 2 & 3) Quote Link to comment
MullinRJ Posted January 15, 2014 Share Posted January 15, 2014 Seth, ???When in doubt, when the pink hammer doesn't work, use the purple hammer. Since Python is practically brand new, it is difficult to debug since the confidence level for the functionality and side effects of each command is low (at least in my opinion). To see if your (un)expected output is a function of your approach or of Python's implementation, I rewrote your code using VectorScript. ???It appears there is a difference in how Python and VS function. Please go over my VS below and verify that I translated your code correctly. If I did, there is an error in Python and not in your approach. With more than 2100 commands, it will take a goodly while to evaluate the entire Python API to the same level as the VS API. Raymond PROCEDURE xxx; CONST CR = chr(13); VAR I, color :Integer; origin :Vector; procedure makeText(a, b, i :Integer); Begin MoveTo(a, b); CreateText(Concat('origin:', Num2Str(1, i), ', ', Num2Str(1, i), CR, 'X:', Num2Str(1, a), ' Y:', Num2Str(1, b))); End; { makeText } procedure makePoints(i :Integer); Begin SetOriginAbsolute(i, i); makeText(-1, 1, i); makeText(0, 1, i); makeText(1, 1, i); makeText(-1, 0, i); makeText(0, 0, i); makeText(1, 0, i); makeText(-1, -1, i); makeText(0, -1, i); makeText(1, -1, i); End; { makePoints } BEGIN GetOrigin(origin.x, origin.y); PushAttrs; TextFont(GetFontID('Arial')); TextJust(2); TextVerticalAlign(3); FillPat(0); Opacity(100); PenSize(5); PenPat(1); RGBToColorIndex(1, 1, 1, color); PenFore(color); PenBack(color); TextSize(6); for I := 0 to 5 do makePoints(I); SetOriginAbsolute(origin.x, origin.y); PopAttrs; SetZoom(50); END; Run(xxx); Quote Link to comment
S. Robinson Posted January 16, 2014 Author Share Posted January 16, 2014 use TextOrigin to set the location of the text center (justification 2 & 3) Good tip. Thanks. Quote Link to comment
S. Robinson Posted January 16, 2014 Author Share Posted January 16, 2014 Since Python is practically brand new, it is difficult to debug since the confidence level for the functionality and side effects of each command is low (at least in my opinion). For me, this exercise is about building some experience in Python and Vectorworks scripting, so I'm ok with the occasional WTF moment. It appears there is a difference in how Python and VS function. Please go over my VS below and verify that I translated your code correctly. If I did, there is an error in Python and not in your approach. With more than 2100 commands, it will take a goodly while to evaluate the entire Python API to the same level as the VS API. You are 100% correct. The behavior is different. cue: Heavens open, angel choir, etc. Thanks for lending me your hammer, Raymond. Seth Quote Link to comment
S. Robinson Posted January 16, 2014 Author Share Posted January 16, 2014 To be thorough, I replaced MoveTo() with TextOrigin() in the example script and tested again. The issue remains. Quote Link to comment
S. Robinson Posted January 16, 2014 Author Share Posted January 16, 2014 Bug submitted. Quote Link to comment
Vectorworks, Inc Employee Vlado Posted May 16, 2014 Vectorworks, Inc Employee Share Posted May 16, 2014 Hi guys, this issue has already been fixed in VW2014 SP3. Regards, Vlado 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.