Hi, I am having problems with dimension after changing the dimscale. The user wants to change the dimscale. The program prompts for the selection of a dimension entity and also for the new dimscale. The dimscale property of the dimension entity is set to the new dimscale. The problem is that the entity is not updated on the screen, even after calling the entity draw method. In VBA there was an Update method, but I can find anything like that in the .NET dimension entity. Can someone help me with this situation? I will really appreciate your help.
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
Hi John,
Can you please try using the "DimRegen" command ?
<code> Application.DocumentManager.MdiActiveDocument.SendStringToExecute("DIMREGEN ", true, false, false); Application.DocumentManager.MdiActiveDocument.SendStringToExecute("REGEN ", true, false, false); </code>
The other way to ensure that the update happens is described here:
http://adndevblog.typepad.com/autocad/2013/01/force-autocad-to-update-the-graphics-display-area.html
Balaji thank you for your suggestions. I tried them all and the dimension still is not updated on the screen. What I want to do is something like selecting a dimension from the drawing, opening the properties window and changing the dimension overall dimscale. The dimension entity is updated immediately after. Here is my code, if you could say what I am doing wrong I will really appreciate. Thanks in advance.
Try Using Trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction peo = New PromptEntityOptions(vbCrLf & "Please select a dimension: ") peo.SetRejectMessage("Please select dimensions only.") peo.AddAllowedClass(GetType(Dimension), False) peo.AddAllowedClass(GetType(AlignedDimension), False) peo.AddAllowedClass(GetType(RotatedDimension), False) peo.AddAllowedClass(GetType(ArcDimension), False) peo.AddAllowedClass(GetType(RadialDimension), False) peo.AddAllowedClass(GetType(OrdinateDimension), False) per = Ed.GetEntity(peo) If per.Status = PromptStatus.OK Then Id = per.ObjectId Else Return False End If BlkTbl = CType(Trans.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable) BlkTblr = CType(Trans.GetObject(BlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) Ent = CType(Trans.GetObject(Id, OpenMode.ForWrite), Entity) If TypeOf (Ent) Is AlignedDimension Then AlignDim = CType(Ent, AlignedDimension) AlignDim.Dimscale = NewDimScale ElseIf TypeOf (Ent) Is RotatedDimension Then RotatedDim = CType(Ent, RotatedDimension) RotatedDim.Dimscale = NewDimScale ElseIf TypeOf (Ent) Is ArcDimension Then ArcDim = CType(Ent, ArcDimension) ArcDim.Dimscale = NewDimScale ElseIf TypeOf (Ent) Is RadialDimension Then RadialDim = CType(Ent, RadialDimension) RadialDim.Dimscale = NewDimScale ElseIf TypeOf (Ent) Is OrdinateDimension Then OrdinateDim = CType(Ent, OrdinateDimension) OrdinateDim.Dimscale = NewDimScale End If Ent.Draw() Trans.Commit() Trans.TransactionManager.QueueForGraphicsFlush() Application.DocumentManager.MdiActiveDocument.SendStringToExecute("DIMREGEN", True, False, False) Application.DocumentManager.MdiActiveDocument.SendStringToExecute("REGEN", True, False, False) Autodesk.AutoCAD.Internal.LayerUtilities.RegenLayers({Ent.LayerId}, Autodesk.AutoCAD.Internal.LayerUtilities.RegenPending) End Using Return True Catch ex As Exception MessageBox.Show(ex.Message, "DimScale Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally DocLock.Dispose() End Try
You don't need most of that code if you only want to update the dimension scale.
The Dimscale property is a property of the Dimension base type, so you don't need all of that if/then/else business that tests the type and casts it to the concrete dimension type.
Just open the selected object and cast it to a Dimension (you don't have to check it first because you're using AddAllowedClass).
After you cast the selected object to a Dimension, and set its Dimscale, call the GenerateLayout() method.
DPhilosopher thank you for your suggestion, the unnecessary code as well. However, this still is not solving the issue. The screen is updated, but the dimensions are in limbo state. They are visible on the screen but they can not be selected, even after calling the regen command. Any suggestion on how to solve this issue.
The code you posted contains a collection of hacks that aren't working, but you didn't bother removing them.
The first hack you need to remove is this:
Ent.Draw()
Second, don't use the TransactionManager from HostApplicationServices.WorkingDatabase.
Use the active document's Transaction manager, and remove the call to QueueForGraphicsFlush(), since the Transaction takes care of that.
Lastly, get rid of the call to SendStringToExecute() to run the DIMREGEN command.
If you're going to hack by trying various things, and they don't solve the problem, don't leave them in the code.
Hi John,
Here is a sample code that I tried with AutoCAD 2012 and the dimension scale took effect correctly.
This is a cleaned up version of your code and most of it are suggestions that DP had already provided.
<CommandMethod("BR")> _ Public Sub DimensionUpdateMethod() Dim activeDoc As Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim ed As Editor ed = activeDoc.Editor Dim peo As PromptEntityOptions peo = New PromptEntityOptions(vbCrLf & "Please select a dimension: ") peo.SetRejectMessage("Please select dimensions only.") peo.AddAllowedClass(GetType(Dimension), False) Dim Id As ObjectId Dim per As PromptEntityResult per = ed.GetEntity(peo) If per.Status <> PromptStatus.OK Then Return End If Dim NewDimScale As Double NewDimScale = 3.0 Id = per.ObjectId Using Trans As Transaction = activeDoc.TransactionManager.StartTransaction Dim BlkTbl As BlockTable BlkTbl = CType(Trans.GetObject(activeDoc.Database.BlockTableId, OpenMode.ForRead), BlockTable) Dim BlkTabr As BlockTableRecord BlkTabr = CType(Trans.GetObject(BlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) Dim Ent As Entity Ent = CType(Trans.GetObject(Id, OpenMode.ForWrite), Entity) Dim dimension As Dimension dimension = CType(Ent, Dimension) dimension.Dimscale = NewDimScale Trans.Commit() End Using End Sub
So, It appears that the issue you are having is specific to AutoCAD Mechanical and there are a few features that do behave differently in the verticals.
In the above post, please refer to "Special Notes on DIMLFAC & DIMSCALE"
Sorry, I dont have a solution to get it working in AutoCAD Mechanical and an expert in the AutoCAD Mechanical discussion forum might be able to help.
Hi DP,
You are right, casting it twice is not needed.
Thanks for correcting that.
Balaji, thank you very much for your help. I tried the code in AutoCAD 2012 and it works as it should. In mechanical I am still having the problem. Also, thanks to DP for your comments they were all well taken.
Can't find what you're looking for? Ask the community or share your knowledge.