Dimension scaling in Block reference

Dimension scaling in Block reference

111Auto302
Enthusiast Enthusiast
2,091 Views
4 Replies
Message 1 of 5

Dimension scaling in Block reference

111Auto302
Enthusiast
Enthusiast

Hi 

 

We are trying to scale dimensions of blocks in AutoCAD using AutoCAD Api. We have created dimensions using Rotated Dimensions and we have set DimScale before creating dimensions. Through this process we are able to increase the size of all the dimensions except dimension size of block reference.

 

Code snippet:

RotatedDimension dim = new RotatedDimension();

dim.DimScale = 120;

dim = new RotatedDimension(rotation, xLine1Point, xLine2Point, dimLinePoint, null, dimStyleId);

 

We have created dimensions in block and then scaled the block. All the dimensions created in the drawing are scaled according to DimScale but the dimension text in block alone are not scaled. Are we missing anything? 

 

Thanks in advance.

0 Likes
Accepted solutions (1)
2,092 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

 

According to your code snippet, you create an instance of RotatedDimension using the default constructor assigned to the 'dim' variable' and set the DimScale of this instance to 120.

Then, you assign 'dim' to a new instance of RotatedDimension using parameters in the constructor but do not set the DimScale of this new instance...

 

You can directly declare, instantiate and set the DimScale property of the 'dim' variable:

RotatedDimension dim = new RotatedDimension(rotation, xLine1Point, xLine2Point, dimLinePoint, null, dimStyleId) { DimScale = 120 };

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

111Auto302
Enthusiast
Enthusiast

Hi _gile,

 

We have tried using the code snippet you have provided but still we are not able to increase the dimension scale of block reference in AutoCAD through API (Arrow of dimensions are increasing but the text size is not increasing). Is there any other possible way to increase the scale of dimensions in block reference?

 

Thanks in advance

0 Likes
Message 4 of 5

deepak.a.s.nadig
Alumni
Alumni
Accepted solution

I have quickly written a sample code to change the Dimscale of a dimension in a block reference. Please test the code on a block reference containing rotated dimension.

 

[CommandMethod("ChangeDimensionInBlk")]
public void ChangeDimensionInBlk() {
	Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
	Database db = HostApplicationServices.WorkingDatabase;
	Transaction tr = db.TransactionManager.StartTransaction();

	// Start the transaction
	try {
		// Build a filter list so that only
		// block references are selected
		TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.Start, "INSERT") };
		SelectionFilter filter = new SelectionFilter(filList);
		PromptSelectionOptions opts = new PromptSelectionOptions();
		opts.MessageForAdding = "Select block references: ";
		PromptSelectionResult res = ed.GetSelection(opts, filter);

		//Enter the dimension scale 
		PromptDoubleResult pdr = ed.GetDouble(new PromptDoubleOptions("Enter a dimscale"));
		if (pdr.Status != PromptStatus.OK)
			return;
		double dimscale = pdr.Value;

		// Do nothing if selection is unsuccessful
		if (res.Status != PromptStatus.OK)
			return;

		SelectionSet selSet = res.Value;
		ObjectId[] idArray = selSet.GetObjectIds();
		foreach (ObjectId blkId in idArray) {
			BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead);
			BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
			ed.WriteMessage("\nBlock: " + btr.Name);

			//block table record...
			BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
			if (blockTable.Has(btr.Name)) {
				blkRef.UpgradeOpen();
				foreach (ObjectId objId in btr) {
					if (objId.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(RotatedDimension)))) {
						RotatedDimension dimen = tr.GetObject(objId, OpenMode.ForWrite) as RotatedDimension;
						try {
							dimen.Dimscale = dimscale;
							//To update the latest updated changes to the block record
							dimen.RecomputeDimensionBlock(true);
						} catch (System.Exception ex) {
							Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
						}
					}
				}
				//set the id of the block
				blkRef.BlockTableRecord = blockTable[btr.Name];
			}
			btr.Dispose();
		}
		tr.Commit();
	} catch (Autodesk.AutoCAD.Runtime.Exception ex) {
		ed.WriteMessage(("Exception: " + ex.Message));
	}
	tr.Dispose();
}

Hope this helps.

 

Message 5 of 5

111Auto302
Enthusiast
Enthusiast

Thank you deepak.a.s.nadig that was helpful

0 Likes