Jump to content
Developer Wiki and Function Reference Links ×

NEED HELP - creating script for object with dims


I3erk

Recommended Posts

I am trying to either find or create a script that will allow me to create an object (like a rectangle) and have the long dimension integrated into the object (placed right above it).

Also, i need the dimension value to change as the objects length changes too.

so if anyone can help me start off with writing this script (never written one before), or if they know if something similar exists already it would be a big help.

Link to comment

Have you considered using associated dimensions for this? With Associated Dimensions turned on (in Document Prefences), you can put dimensions that will change as the object changes.

If you draw a rectangle and put an associated dimension on it, it will move with the object and change as the rectangle changes length. If you really want only a single object, you could group the rectangle and dimension together.

Is there some special reason you thing you need a script to do this? What is it you are really trying to do. There might be easier ways to do it.

If you do decide to script it, it will probably need to be a Plug-In Object so the dimension will update when you change the rectangle. Not hard, but multiple hours of work especially if you put the learning curve into it.

Pat

Link to comment

Hey Pat, thanks.

what i am trying to do in the end is to have like beams, joists and such, with the dimension attached to it and showing without having to draw and attach a dimension line to the object.

having a plug-in object like this will make it much easier since the drawings and plans could have tons of wall/floor parts in the same area. It would be a pain in the ass to have to draw all the dimensions lines for each object.

so thats pretty much why i would need something like this.

Link to comment

OK, try this and see what you think.

Go to the Tools menu : Scripts : VectorScript Plug-In Editor

Click the New button. Give the plug-in a name. I suggest starting it with an exclaimation point! this will get it to sort to the top of the list. Click the Rectangle Object button and click OK.

Click the Script... button and paste the following into the editor window and click OK.

{*********** Copy from Here ***********}

Procedure DimmedRect;

Begin

Rect(0,-pBoxWidth/2,pLineLength,pBoxWidth/2);

Moveto(0,0);

Lineto(pLineLength,0);

DimText;

End;

Run(DimmedRect);

{*********** To Here ***********}

Click the Done button.

Go into the workspace editor and add your new tool to a tool palette.

As written, this will let you draw a line down the center of the object and then across half the bottom (while ghosting both sides.)

This is just a very basic start, but might give you an idea.

Pat

Link to comment

Thanks alot. This should get me started pretty well.

1 thing tho, is there a way to show a dimension and not have the dimension ticks showing ? ( like in architecture, they are -/---------DIM---------/- so like, to get rid of those " / " while still having the dimension value show.

thanks again

Link to comment

Since it is a true dimension, it is being drawn using the active dimension standard (set in the document preferences).

You could create a custom dimension standard and then switch to that standard before you draw the line and then switch back before you leave the script. The trick will be to add the dim standard to your template file and make sure that no one moves it to a different position in the list as it is strictly a numerical position index.

You will also need to make a custom marker standard to use either arrows instead of ticks or to have a marker type that is so small that you can't see it. I make a rectangular marker with dimensions of Zero. You can do this either from the Attributes Pallette or from Tools:Options:Edit Marker List. Use this marker in your custom Dim Standard.

The following should be close to what you want as long as you only have a single custom dim standard set to zero size markers.

Procedure DimmedRect;

Var OldStd:Integer;

Begin

OldStd:=GetPrefInt(71);

SetPrefInt(71,0);

Rect(0,-pBoxWidth/2,pLineLength,pBoxWidth/2);

Moveto(0,0);

Lineto(pLineLength,0);

DimText;

SetPrefInt(71,OldStd);

End;

Run(DimmedRect);

Pat

Link to comment

What do you mean? Right now it puts the dim line right down the middle.

It is the lines Moveto(0,0); and Lineto(pLineLenght,0);

You can move it in the width direction by changing the last zero in both of those two lines. If you want a "vertical" line, then make sure you use the same thing in both.

You can do whatever kind of math you want using the pBoxWidth to determine where to set the line.

Pat

Link to comment

is there a way to place the dim line overlapping the top line of the rectangle instead of right thought the middle. that way the dim line will always move with the object and the dim text will always be in the same relative location above the rectangle.

cuz right now the dim line is thought the middle, but the text is set at a certain distance away from the dim line. as the rectangle's width gets larger, the dim line still is thought the middle of the rectangle but the dim text remains at that same distance away from the dim line, so instead of the text being above the rectangle, its ends up inside it.

so what i am wondering is if there is a way to make sure the text stays above (and outside) the rectangle, even when the width increases or decreases ?

Link to comment

15 years of MiniPascal and VectorScript playing and about 1 million lines of Pascal prior to that.

A good place for you to start is in the VW help. From VW select Help and then VectorScript Guide and the VectorScript Reference.

Also from the VectorScript Reference go to Additional Resources and select the VectorScript Appendix.

If I where you, I would bookmark all three of the above places in my browser if you are going to do much scripting.

I actually have the VectorScript Reference open in three tabs in by browser so I can look up multiple functions/procedures at the same time.

I recommend that you read the VS Guide, and then go through the script and look up all of the commands in the VectorScript Reference. That will give you a starting point for doing more.

You are welcome.

Pat

Link to comment

In the PIO Editor you will click the Parameters button and add a new parameter and set it to be a type of Boolean.

In the script put an IF statement around the two lines that draw the dimension. Use a p before the name of the new parameter as part of the if statement.

If pNewParameter then

Begin

Draw Dim Here;

End;

Pat

Link to comment

so it would be

Procedure DimmedRect;

Var OldStd:Integer;

Begin

OldStd:=GetPrefInt(71);

SetPrefInt(71,0);

Rect(0,-pBoxWidth/2,pLineLength,pBoxWidth/2);

Moveto(0,pBoxWidth/2);

Lineto(pLineLength,pBoxWidth/2);

If pTEXT then

DimText;

SetPrefInt(71,OldStd);

End;

Run(DimmedRect);

Link to comment

I would move the If to above the Moveto

If pTEXT then

Begin

moveto

etc.

DimText;

end;

SetPrefInt(

For else then some thing like

If pText then

Begin

end

else

Begin

end;

Note that there is not semicolon after the end before the else.

If you add a parameter it will show in the OIP however you have it defined.

Since the dim line is along the side of the box and you don't want markers, why draw it at all if you don't want the text? If you don't draw it then you don't need the else.

If checked then dim else do nothing.

If you want to take this any further, you really need to read the VSGuide and start digging into the Function Reference.

Pat

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...