Jump to content
Developer Wiki and Function Reference Links ×

Get a dimension's length in document unit precision


Juliensv

Recommended Posts

Hey y'all,

 

I'm trying to get the length of an existing dimension, but I'm not sure how to go about it. I can get the "text" of the dimension with GetDimText but it's rounded to the dimension precision, and it's also a string which I need to parse to get the actual value. I'd like to get a REAL in the document unit precision.

 

I've tried multiple methods, Hlength, HPerim, , which haven't garnered good results. The closest I can get is using Get2DPt, which works with aligned dimensions, but it's complicated with Linear Dimensions that have different offsets on each witness line, because Get2DPt only gives the location of the end of each witness line. I've tried screwing around with the witness line override selectors but that doesn't change the Get2DPt.

 

Dimension Offset selector 45 only gives the length of the "first" witness line, so there's nothing to compare to figure out the orientation/offset of a constrained linear dim.

 

Do y'all have any ideas how to get this? I'm sure I'm missing an obvious answer.  Thanks in advance!

Link to comment

I don't think what you want exists.

 

I used ValidNumberString to convert the text value into a Real in a Worksheet Script I was playing with.

 

Procedure Test;

Var	B1:Boolean;
	R1:Real;
Begin
	B1:=ValidNumStr(GetDimText(WSScript_GetObject),R1);
	WSScript_SetResReal(R1);
End;

Run(Test);

 

That should get you the value with the "correct" document units, but test and see.

 

You may need to script your own routine to take a Real and "round" it to the document units precision.

 

HTH

  • Like 1
Link to comment

@Juliensv,

   Are you wanting the value to use in a worksheet, or just in a script? For accessing the length in a script, here's an example that shows the exact length in document units but w/o the units string displayed.

 

PROCEDURE xxx;
{ Show the length of a selected dimension object. }
{ 10 Nov 2023 - Raymond J Mullin }
VAR
	H :Handle;
	B :Boolean;
	P1, P2 :Vector;
BEGIN
	H := FSActLayer;
	if (GetTypeN(H) = 63) then begin		{ Dimension object }
		B := GetObjectVariablePoint(H, 13, P1.x, P1.y, P1.z);		{ point 1 }
		B := GetObjectVariablePoint(H, 14, P2.x, P2.y, P2.z);		{ point 2 }
		AlrtDialog(concat('Dimension Length  =  ', Norm(P2-P1)));	{ display length }
	end		{ if }
	else AlrtDialog('Selected object is not a DIMENSION object.');
END;
Run(xxx);

 

   If you want to control the number of decimals displayed in the answer, use the Num2Str() function around the Norm() function, or if you want the answer formatted using the current document units, use the Num2StrF() function. Lastly, if you want the answer for use in a Worksheet function, a some lines will need to be added and removed.

 

HTH,

Raymond

  • Like 1
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...