Community
Is it really this difficult to set a dimscale in an existing drawing to the current one? Geez. I've been googling for way too long without a result. Hoping someone here can set me on the right path. So I have two remaining questions. #1 - How can I fix the code below to set an existing dim style to be the current one. I'd like to pass in a name of the Dim Style and have it become active. #2 - How can I loop through the dim style table to view all the available dim styles. Thanks in advance.
<CommandMethod("MyTest")> _ Public Sub MyTest() '' Get the current database Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the DimStyle table for read Dim acDimStyleTbl As DimStyleTable acDimStyleTbl = DirectCast(acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead), DimStyleTable) For Each objectid As ObjectId In acDimStyleTbl MessageBox.Show(objectid.ToString) Next '' Commit the changes and dispose of the transaction acTrans.Commit() End Using End Sub
You can try this, you can pass a dimension name and scale.
<CommandMethod("MyTest")> _ Public Sub MyTest(ByVal DimName As String, ByVal DimScale As Double) '' Get the current database Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the DimStyle table for read Dim acDimStyleTbl As DimStyleTable acDimStyleTbl = DirectCast(acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead), DimStyleTable) Dim DimTblRec As DimStyleTableRecord For Each objectid As ObjectId In acDimStyleTbl DimTblRec = CType(acTrans.GetObject(objectid, OpenMode.ForRead), DimStyleTableRecord) MessageBox.Show(DimTblRec.Name) Next If acDimStyleTbl.Has(DimName) = True Then DimTblRec = CType(acTrans.GetObject(acDimStyleTbl(DimName), OpenMode.ForWrite), DimStyleTableRecord) DimTblRec.Dimscale = DimScale acCurDb.Dimstyle = DimTblRec.ObjectId acCurDb.SetDimstyleData(DimTblRec) Else 'Add code to handle this End If '' Commit the changes and dispose of the transaction acTrans.Commit() End Using End Sub