By Wayne Brill
This example shows how to scale drawing dimensions. All the dimensions will be scaled regarding on which drawing view they belong:
Here is the workflow:
Collect the dimensions related to a particular view
For each dimension, get the text origin in sheet space
Compute text origin in view space
Scale the text coordinates
Compute the new scaled position in sheet space, and set it back to the dimensions
For example, you can use the procedure with a small scale factor (close to 1.0, lets say 0.9), couple of times, at each time all the dimensions should come closer to the drawing view on which they are related. By doing this the alignment of all the dimensions will be kept. Also a scale factor greater than 1.0 will have the effect of stretching up the drawing dimensions.
Download ScaleDrawingDimensions
Here is the code from the example:
publicvoid ReframeDimensions()
{
try
{
DrawingDocument oDrawingDoc =
(DrawingDocument)ThisApplication.ActiveDocument;
Sheet oSheet = oDrawingDoc.ActiveSheet;
double ScaleFactor = 0.5;
foreach (DrawingView oDwgView in
oSheet.DrawingViews)
{
//Collect Dimensions related to
//the current DrawingView
ObjectCollection oObjCollection =
GetDrawingDimForView(oSheet, oDwgView.Name);
// Iterate through all the drawing
// dimensions for this view
foreach (object obj in oObjCollection)
{
DrawingDimension oDwgDimIterator =
obj asDrawingDimension;
DimensionText oDimensionText =
oDwgDimIterator.Text;
//Get text position in
//DrawingView space
Point2d oPosInView = oDwgView.
SheetToDrawingViewSpace(oDimensionText.Origin);
//Scale the text coordinates by
//our scale factor
Point2d oNewPosInView =
ThisApplication.TransientGeometry.
CreatePoint2d(oPosInView.X * ScaleFactor,
oPosInView.Y * ScaleFactor);
//Convert new position in sheet space
Point2d oNewPosInSheet = oDwgView.
DrawingViewToSheetSpace(oNewPosInView);
//Reframe dimension in sheet
oDimensionText.Origin = oNewPosInSheet;
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
publicObjectCollection GetDrawingDimForView
(Sheet oSheet, string ViewName)
{
ObjectCollection oDrawDimsForView =
ThisApplication.TransientObjects.
CreateObjectCollection(null);
DrawingDimensions oDrawDims =
oSheet.DrawingDimensions;
foreach (DrawingDimension oDrawDimIterator
in oDrawDims)
{
switch (oDrawDimIterator.Type)
{
caseObjectTypeEnum.
kLinearGeneralDimensionObject:
{
LinearGeneralDimension oLinearDim =
oDrawDimIterator asLinearGeneralDimension;
DrawingCurve Curve =
oLinearDim.IntentOne.Geometry asDrawingCurve;
DrawingView DwgView =
Curve.Parent asDrawingView;
if (string.Compare
(DwgView.Name, ViewName) == 0)
{
oDrawDimsForView.Add(oDrawDimIterator);
}
}
break;
caseObjectTypeEnum.
kRadiusGeneralDimensionObject:
{
RadiusGeneralDimension oRadiusDim =
oDrawDimIterator asRadiusGeneralDimension;
object obj = oRadiusDim.Intent.Geometry;
DrawingCurve Curve =
oRadiusDim.Intent.Geometry asDrawingCurve;
DrawingView DwgView =
Curve.Parent asDrawingView;
if (string.Compare
(DwgView.Name, ViewName) == 0)
{
oDrawDimsForView.Add(oDrawDimIterator);
}
}
break;
caseObjectTypeEnum.
kDiameterGeneralDimensionObject:
{
DiameterGeneralDimension oDiameterDim =
oDrawDimIterator asDiameterGeneralDimension;
object obj = oDiameterDim.Intent.Geometry;
DrawingCurve Curve =
oDiameterDim.Intent.Geometry asDrawingCurve;
DrawingView DwgView =
Curve.Parent asDrawingView;
if (string.Compare(DwgView.Name,
ViewName) == 0)
{
oDrawDimsForView.Add(oDrawDimIterator);
}
}
break;
caseObjectTypeEnum.
kAngularGeneralDimensionObject:
{
AngularGeneralDimension oDiameterDim =
oDrawDimIterator asAngularGeneralDimension;
DrawingCurve Curve =
oDiameterDim.IntentOne.Geometry asDrawingCurve;
DrawingView DwgView =
Curve.Parent asDrawingView;
if (string.Compare(DwgView.Name,
ViewName) == 0)
{
oDrawDimsForView.Add(oDrawDimIterator);
}
}
break;
default:
break;
}
}
return oDrawDimsForView;
}