Jump to content
Developer Wiki and Function Reference Links ×

draw lines by angle + distance


Recommended Posts

i'm trying to convert an old microstation

script to draw site diagrams, but cant'

find a function in vectorscript to draw a

line by distance + angle.

in microstation the script is:

place smartline

xy=0,0

DI=,

DI=,

DI=,

DI=, etc...

xy=0,0

in vectorscript i can only find

LineTo(X,Y);

is there a vector equivalent?

any help would be much apreciated...

regards

gideon scott

Link to comment

Hi Gideon,

You have to convert your distance and angle to X & Y displacement, but it can be done with a few lines of code.

MoveTo(X, Y); { Draw first point }

A := Deg2Rad(A);

dX := L * cos(A);

dY := L * sin(A);

LineTo(X+dX, Y+dY); { Draw last point }

where L = Length, and A = Angle in degrees.

You can also do it with vector math, but it's pretty much the same approach.

Raymond

Edited by MullinRJ
Link to comment

But the beauty of scripting is you only have to type it once.

If you want to be able to use the code in your script to draw several lines, define a procedure with the code and call it once per line you want to draw.

	procedure LinePolar(X, Y, L, A :Real);
{ Draw a Line from point (X, Y) to another point specified by length L and angle A (in degrees). }
Begin
	A := Deg2Rad(A);		{ change A to radians }
	MoveTo(X, Y); 			{ Move to first point }
	LineTo(X+L*cos(A), Y+L*sin(A)); { Draw to second point }
End;		{ LinePolar }

Instesd of MoveTo(); and LineTo(); calls to draw a line, use:

LinePolar(1, 2, 5, 53.1301);

which is the same as:

MoveTo(1, 2);

LineTo(4, 6);

The same could be done for LineToPolar(), which you may want to use if you are chaining segments together. Let me know, or try your hand at it. It's not hard. Though, if that's the case, you probably should be using Polygons.

HTH,

Raymond

Link to comment

raymond

thanks for the help,

in the end i've got my external spreadsheet,

where i enter the site data, to do all the

geometry calculations + generate an 'include'

text file.

the weird thing now is that the import script

that pulls the file in works the 1st time i

use it, but if i edit the external worksheet,

regenerate the 'include' file, and run the

import again it draws the original site shape,

not the updated shape. i've checked that the

'include' file is correctly updating, but it

seems that the original data is lurking in

some cache. if i recompile the import script

the updated shape is drawn correctly the

1st time the script is re-run, but thereafter

it doesn't update again.

is there a way to 'flush' the include file

from memory?

Link to comment
i've checked that the

'include' file is correctly updating, but it

seems that the original data is lurking in

some cache

The original data is linked via ObjectID# > #include container which then imports the FilePath data.

Recompiling the script requires the #Include container to import the #Include data from the designated FilePath.

Perhaps, a FilePath dialog would work to reset the contents of the #include container

Link to comment

This is 'compiler mode'. If you have an industry series product there's a menu command somewhere under scripts to turn script caching on and off.

If you're using fundamentals add SetPref(407, True) to stop caching plug-in scripts. You might want to make a pref toggle script to turn caching on and off as needed.

Edited by ccroft
Link to comment

Hi Gideon,

Leaving that preference ON will noticeably slow down all PIO scripts, especially the big ones. When developing PIO scripts I leave it on all the time, and toggle it off when I want to see how a script will perform in reality. Under normal operating scenarios I leave it OFF.

Raymond

Link to comment
  • 2 weeks later...

Perhaps, a FilePath dialog would work to reset the contents of the #include container

islandmon, can you give me a clue how to do this?

i've got my diagrams working well using the distance-angle

mode, but still have to manually run a 'SetPref(407, True)'

script in advance. adding this into the diagram script

doesn't work.

any advice would be appreciated.

Link to comment

Gideon

If you can restructure things in a way that allows you to use standard File I/O type calls like ReadLn instead of Include, I don't think you'll have the caching prob.

I have Menu Commands that use GetFile, and the data is read anew each time. GetFile uses a dialog to select the file though, and this isn't something you usually want in a VSO since it will be displayed anytime Objects are regenerated. I'm not 100% sure what will happen if you use Open(filename), but you'd think it would be the same.

It sounds like you are exporting a delimited text file from Excel that has all the distance/angle info and your PIO does the rest. File i/o is designed for this kind of work, and is used in some of the standard PIO's to read files in the Data folder in PlugIns folder.

I'm not sure how you are using Include for this. I've only used it for importing code.

Charles

Link to comment

charles

thanks for that, but your tips are a bit beyond me,

+ i can't figure how to get my file in that way.

my spreadsheet converts local site data, which

comes in a variety of units + as either XYZ or

distance/angle format, into metric + then

outputs a text file to draw the site poly

eg.

BeginPoly;

MoveTo(0,0);

LineTo(10m,#45d0'0");

LineTo(10m,#-45d0'0");

LineTo(10m,#-135d0'0");

LineTo(11m,#-225d0'0");

ClosePoly; EndPoly;

i've tried modifying my spreadsheet output to be

able to use the 'import survey file' function,

which works fine, but doesn't draw the site poly...

Link to comment

charles

the $include file varies by the complexity

of the site, but is basically as follows:

TextFont(GetFontID('Arial')); TextSize(12);

BeginPoly;

MoveTo(0,0); BeginText; 'a' EndText;

LineTo(10m,#45d0'0"); BeginText; 'b' EndText;

LineTo(10m,#-45d0'0"); BeginText; 'c' EndText;

LineTo(10m,#-135d0'0"); BeginText; 'd' EndText;

LineTo(11m,#-225d0'0");

ClosePoly; EndPoly;

Link to comment

Maybe I totally mis-understand what's going on here. You mean to say that you're writing all this in Excel? I'm wondering what the raw Excel data looks like.

Typically the way this works is to export only the numbers needed for drawing from Excel as a delimited text file...it's just a structured list of values. The vScript contains the drawing code. It only reads the values from the text file. The code is in the plugin, and the data is in the text file.

If you would like to email me an Excel file, maybe I can help you further. Sending the PIO wouldn't hurt either.

chacroATshaw.ca (old habit...don't know if spambots get in here or not)

Charles

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...