.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Placement of Dimension Line/Text

2 REPLIES 2
Reply
Message 1 of 3
bob4963
484 Views, 2 Replies

Placement of Dimension Line/Text

I'm using AutoCAD 2007 and VB.net 2005. The VB.net code below works fine except that the Dimension line and Text are not off-set from the object I'm dimensioning. The dimension line is directly inline with the points that I want to dimension. I would like the Dimension line and Text to be 1/2" offset from the object I am dimensioning.

Does anybody know how to modify this code so the dimension line will be 1/2" away from the object?

Thanks for your help,

Private Function CreatedDim(ByVal x1, ByVal y1, ByVal x2, ByVal y2) As ObjectId

Dim pt1 As New Geometry.Point3d(x1, y1, 0)
Dim pt2 As New Geometry.Point3d(x2, y2, 0)
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim myTransMan As DatabaseServices.TransactionManager = db.TransactionManager
Dim myTrans As Transaction = myTransMan.StartTransaction()
Dim newActLayerName, strLayerColor, intLineWt As String
strLayerColor = "Red"
intLineWt = "015"
newActLayerName = "TEXT"
ChangeLayer(newActLayerName, strLayerColor, intLineWt)

Using myTrans
Dim bt As BlockTable = myTrans.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = myTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
Dim rd As New RotatedDimension
rd.XLine1Point = pt1
rd.XLine2Point = pt2
rd.TextAttachment = AttachmentPoint.TopMid
btr.AppendEntity(rd)
myTrans.AddNewlyCreatedDBObject(rd, True)
myTrans.Commit()
End Using

myTrans.Dispose()
myTransMan.Dispose()
End Function
2 REPLIES 2
Message 2 of 3
cjmprog
in reply to: bob4963

I think you need 'TextLineSpacingFactor'.

I hope below sample code is useful for you.

'#### code ######
Dim DimApi As New Autodesk.AutoCAD.DatabaseServices.AlignedDimension

DimApi.UsingDefaultTextPosition = True
DimApi.TextLineSpacingStyle = LineSpacingStyle.AtLeast
DimApi.TextLineSpacingFactor = 2
DimApi.TextAttachment = AttachmentPoint.BottomCenter
DimApi.TextPosition = Request.Dims.TxtInsertPoint Message was edited by: cjmprog
Message 3 of 3
bob4963
in reply to: bob4963

Below is the amended code. Your line of code " DimApi.TextPosition = Request.Dims.TxtInsertPoint " generated errors saying that Request was not declared. What should it be declared as? Also it says that Dims is not part of AlignedDimension.

The code below runs fine and does not generate errors but the Dimension line is still placed on the 0 x axis no matter where the object is located.

Do you have an idea of what is wrong? Also, should there be an AppendEntity(DimApi) statement? If so what Block Table Record should it be associated with?

Thanks for your help,


Private Function CreateDim(ByVal x1, ByVal y1, ByVal x2, ByVal y2) As ObjectId

Dim pt1 As New Geometry.Point3d(x1, y1, 0)
Dim pt2 As New Geometry.Point3d(x2, y2, 0)
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim myTransMan As DatabaseServices.TransactionManager = db.TransactionManager
Dim myTrans As Transaction = myTransMan.StartTransaction()

Using myTrans
Dim bt As BlockTable = myTrans.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = myTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
Dim rd As New RotatedDimension
Dim DimApi As New Autodesk.AutoCAD.DatabaseServices.AlignedDimension

rd.XLine1Point = pt1
rd.XLine2Point = pt2
DimApi.UsingDefaultTextPosition = True
DimApi.TextLineSpacingStyle = LineSpacingStyle.AtLeast
DimApi.TextLineSpacingFactor = 2
DimApi.TextAttachment = AttachmentPoint.BottomCenter

btr.AppendEntity(rd)
myTrans.AddNewlyCreatedDBObject(rd, True)

myTrans.Commit()
End Using

myTrans.Dispose()
myTransMan.Dispose()
End Function

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost