orlando Teixeira Posted July 14, 2008 Share Posted July 14, 2008 Hello people i started working with vectorworks last month , migrated from cad, and i am just loving it I used a tool called x-line that doesnt exist in vectorscript and i am an adicted to it. Is it possible to make such a script. it is simple in logic but i dont know how to vectorscript so for me is complicated. so the logic is : 1-pic point (where we want the line to begin) 2-pic second point (direction of line) the script will do the rest : after the 2 points will create a line with for example 100 meters in the direction that we gave in the second point and if selected (in proprieties for example) it will convert automatic in a guide. how can i do that ? thx in advanced ps. i am using Architect 2008 Quote Link to comment
maarten. Posted July 14, 2008 Share Posted July 14, 2008 Something like this should do the trick: PROCEDURE MakeGuide; VAR x1, x2, y1, y2 : REAL; BEGIN GetPt(x1,y1); GetPtL(x1,y1,x2,y2); MoveTo(x1,y1); LineTo(x2,y2); DoMenuTextByName('Guides',1); END; RUN(MakeGuide); Quote Link to comment
orlando Teixeira Posted July 14, 2008 Author Share Posted July 14, 2008 maarten, thx the answer was easyer than i thought but it misses just a thing I did not run it yet but it seems that it will ask me a point, than 2 points (a line) and then it will draw a line from x1, y1 to x2, y2 correct ? I want it to when i click second point it will do a line that direction but with an fixed distance allready in script for example 1000. so can i do something like: Code:PROCEDURE MakeGuide; VAR x1, x2, y1, y2 : REAL; BEGIN GetPt(x1,y1); GetPt(x2,y2); MoveTo(x1,y1); LineTo((x2,y2)+1000); DoMenuTextByName('Guides',1); END; RUN(MakeGuide); Quote Link to comment
maarten. Posted July 14, 2008 Share Posted July 14, 2008 Ah, sorry, I got that wrong. This would work, although it's not completly by the art of scripting PROCEDURE MakeGuide; VAR x1, x2, y1, y2 : REAL; ang : REAL; BEGIN GetPt(x1,y1); GetPtL(x1,y1,x2,y2); MoveTo(x1,y1); LineTo(x2,y2); ang:=HAngle(LNewObj); DelObject(LNewObj); MoveTo(x1,y1); LineTo(x1+1000,y1); HRotate(LNewObj,x1,y1,ang); DoMenuTextByName('Guides',1); END; RUN(MakeGuide); GetPtL just draws a temporary "rubberband" to give a visual reference of the line you're drawing. If you don't want that, you can ofcourse replace that line by GetPt(x2,y2);. Quote Link to comment
orlando Teixeira Posted July 14, 2008 Author Share Posted July 14, 2008 Thx maarten that worked like a charm you made my lfe easier do you have or do you know where can i learn more about vectorscript ? i dont know why but i cant get to understand nemstek manual .... Quote Link to comment
orlando Teixeira Posted July 14, 2008 Author Share Posted July 14, 2008 (edited) maarten why are you creating and then erasing and creating the line againg ? i understand its because of the angle and direction of it, but cant you create the first line and then just give it more lenght ? or is there any "command" that associted with getptl() will give the angle (or something like that?) sorry maarten, i am not messing with you i am just curious. In theory i know how to do it but in practice .... hehehe thats why i am a "greenhorn" lolololol Edited July 14, 2008 by orlando Teixeira Quote Link to comment
maarten. Posted July 15, 2008 Share Posted July 15, 2008 Well, there are other ways of doing it of course, you could calculate the coordinates of the long line with Pythagoras. That way you wouldn't need to draw the temporary line first to delete it afterwards... Or you could scale the line by a curtain factor, but it will always scale the line from it's midpoint, and i'm not sure if it's that what you want. So, i just choose for the simple way, draw a temporary line, get the angle of it, delete the line, draw a new line with the right length and then rotate it. Very easy to script, but (as i said) not completely by the Art of Scripting . As far as i know, there's no direct way of increasing the length of a line with Vectorscript. Here's the code again, this time the coordinates are calculated. I do advice you though, to put the units behind the Length = 1000;, cause otherwise VS will take the units that are active in the document. So if you have mm set as the document's unit, the line will only be 1 meter long, and i think that's a little bit to short. So better is to make that line Length = 1000m; or any other unit you want, or even any other length that you want. It's always better to use units in your scripts, otherwise you can get some pretty strange results sometimes. PROCEDURE MakeGuide; CONST Length = 1000; {the length of the line} VAR x1, x2, y1, y2 : REAL; {the coordinates of the two mouse clicks} a : REAL; {the horizontal length between the two mouse clicks} b : REAL; {the vertical length between the two mouse clicks} c : REAL; {the length between the two mouse clicks} BEGIN GetPt(x1,y1); GetPtL(x1,y1,x2,y2); a:=x2-x1; b:=y2-y1; c:=Sqrt(Sqr(a)+Sqr(b)); MoveTo(x1,y1); LineTo(x1+(a*(Length/c)),y1+(b*(Length/c))); DoMenuTextByName('Guides',1); END; RUN(MakeGuide); To learn Vectorscript... Well, i took a 3 day lesson here in Flanders where i learned the basic of it. All the rest i learned by selfstudy, reading a lot of other scripts and with a lot of help from advanced scripters. If you have any more questions, just ask and i'll try to answer them as i can . Quote Link to comment
orlando Teixeira Posted July 15, 2008 Author Share Posted July 15, 2008 Hello again maarten good morning well, nice change. pitagoras kicks ass ok i will take your advice and study other scripts every time i have an question before i ask someone. therefore i can learn by myself also. you said :"As far as i know, there's no direct way of increasing the length of a line with Vectorscript." i reply : i sugested that because we can do it in the object info palette so i thought it was possible somehow , thats why i am a rookie ok thx for the great help you gave me. when i need i will come back for sure thx again maarten Quote Link to comment
Miguel Barrera Posted July 15, 2008 Share Posted July 15, 2008 maarten and orlando You can change the length of the line by setting the end point location such as: PROCEDURE SetSegPt2(h :HANDLE; pX, pY :REAL); In your original script where the line is drawn first, it can be changed afterwards also. PROCEDURE MakeGuide; CONST kLENGTH = 1000; VAR x1, x2, y1, y2 : REAL; ang : REAL; lineVec: VECTOR; BEGIN GetPt(x1,y1); GetPtL(x1,y1,x2,y2); MoveTo(x1,y1); LineTo(x2,y2); ang:=HAngle(LNewObj); lineVec:= Ang2Vec(ang,kLENGTH); x2:= x1 + lineVec.x; {or lineVec[1]} y2:= y1 + lineVec.y; {or lineVec[2]} SetSegPt2(LNewObj,x2,y2); DoMenuTextByName('Guides',1); END; RUN(MakeGuide); and like in the your last script, you can also calculate the end point first and then draw the line. I prefer working with vectors because they have direction. If you use geometry, you are only calculating the length "c". Quote Link to comment
maarten. Posted July 16, 2008 Share Posted July 16, 2008 Thanks Miguel, didn't knew that! I've never really worked with Vectors cause i've no idea how they work. I don't understand the part about Vectors in The VS Language Guide, but i'll try it again. Thanks again . Quote Link to comment
orlando Teixeira Posted July 16, 2008 Author Share Posted July 16, 2008 (edited) hello miguel and maarten well, all i got to say is that i am starting to like it more and more Is it strange that i cant find that info in the vs manual ? perhaps its me that dont understand it he!he!he!he! can i ask both of you if you find me some links or manual more for newbiews because all i can find is manuals for those who allready know something about scripting.... thx for all the help given to me Edited July 16, 2008 by orlando Teixeira Quote Link to comment
maarten. Posted July 17, 2008 Share Posted July 17, 2008 Well, the VS Language Guide has an introduction to VS. You can find it in the Help-folder in your VW aplication folder. Best is to bookmark that page. It's a long read though. I first learned my basic by making very easy scripts (like scripting a line, a rectangle, arc,... or rotating, scaling, flipping objects). Then i also looked at the code of simple scipts from others (you can find a lot of them on boards), looked what they did, try to understand it and looked op every procedure and function in the VS Function Reference (could also be found in the Help-Folder). When i found something that wasn't in the Func Ref, i looked it up in the Lang. Guide. It's also very handy to post your first scripts and let advanced user comment them. You learn a lot of new things by doing that! I hope that was of some help. Quote Link to comment
Miguel Barrera Posted July 17, 2008 Share Posted July 17, 2008 orlando Vectorscript is based on the Pascal language which in the 80's was the language of choice and most Mac applications, including MiniCad (alias Vectorworks), were developed with it. You can learn the structure and sintax of a program with any Pascal programming language book. Besides the NNA vectorscript support pages, the Vectorlab is a good source for information and examples. http://www.vectorlab.info/index.php?title=Category:VectorScript Quote Link to comment
orlando Teixeira Posted July 21, 2008 Author Share Posted July 21, 2008 good morning miguel and maarten thx again for the help. as usual when i try to start to learn something usually i run out of time for a couple of weeks hehehe but i will try i certanly will come back thank you Quote Link to comment
Markus Barrera-Kolb Posted August 5, 2008 Share Posted August 5, 2008 Thanks for the scripts! Coming from AutoCad I also find the construction line function useful. The posted scripts seem to be a bit more like the Ray function, in that the line only shoots off in one direction. I made a humble attempt at a script that would extend it in both directions, by simply scaling the line drawn between the two points (in this case by a factor of 1000). I made the script into a tool, but it'll only let me draw one line. To draw a second one, I have to exit the tool and then re-select it. Any idea why or how to correct this? Thanks! PROCEDURE DrawXline; VAR x1, x2, y1, y2 : REAL; BEGIN GetPt(x1,y1); GetPtL(x1,y1,x2,y2); MoveTo(x1,y1); LineTo(x2,y2); Scale(1000,1000); END; RUN(DrawXline); Quote Link to comment
Pat Stanford Posted August 5, 2008 Share Posted August 5, 2008 It is drawing all of your lines, but is leaving them selected. Then when you try to put in the next line, it scales from the center of the two selected object and moves them way off in space. Put a DSelectAll; at the beginning of the script and it will work fine. You may also want to add a DSelectAll; at the end as well so the new construction line is not left selected. I troubleshot this by setting the scale to a small (2,2) value so I could really see what was happening. Pat Quote Link to comment
Markus Barrera-Kolb Posted August 5, 2008 Share Posted August 5, 2008 Right you are, thanks Pat! It's obvious once someone smarter points it out... 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.