- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to make a command that the user selects items in the drawing and the goal is to remove the current annotative scales for that item and move it to the current set annotative scale. i dont just want to add the current it needs to remove the old ones first.
the reason why i split the different objects is because i assume that they all have different ways to set the annotative scales. the alert dialog box was to check if i selects a correct object. This Is what i have so far but i am stuck
public void AttachToCurrentAnnoScale()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor edt = doc.Editor;
ObjectContextManager ocm = db.ObjectContextManager;
ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
AnnotationScale currentAnnoScale = db.Cannoscale;
Application.MainWindow.Focus();
using (DocumentLock docLock = doc.LockDocument())
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//Create TypedValue
TypedValue[] types = new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<or"),
new TypedValue((int)DxfCode.Start, "INSERT"),
new TypedValue((int)DxfCode.Start, "MTEXT"),
new TypedValue((int)DxfCode.Start, "MULTILEADER"),
new TypedValue((int)DxfCode.Start, "DIMENSION"),
new TypedValue((int)DxfCode.Operator, "or>")
};
//Create SelectionFilter
SelectionFilter filter = new SelectionFilter(types);
//Create PromptStringResult
PromptSelectionResult selResult = edt.GetSelection(filter);
//Selection Verification
if (selResult.Status == PromptStatus.OK)
{
//Create Selection Set
SelectionSet ss = selResult.Value;
//Loop Thru Selection Set
foreach (SelectedObject selObj in ss)
{
DBObject dbobj = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite);
if (dbobj != null)
{
//Check For Block
if (dbobj is BlockReference blockref)
{
Application.ShowAlertDialog("You Selected a Block");
}
//Check For Mtext
if (dbobj is MText mtext)
{
mtext.Annotative = AnnotativeStates.True;
Application.ShowAlertDialog("You Selected a MTEXT");
}
//Check for MLeader
if (dbobj is MLeader mleader)
{
mleader.Annotative = AnnotativeStates.True;
Application.ShowAlertDialog("You Selected a MLeader");
}
//Check for Dimension
if (dbobj is Dimension dim)
{
dim.Annotative = AnnotativeStates.True;
Application.ShowAlertDialog("You Selected a Dimension");
}
}
}
trans.Commit();
edt.WriteMessage("\nObject Moved to Current Annotation Scale.");
}
else
{
edt.WriteMessage("\nNo valid entities selected. Ensure the correct types are being selected.");
}
}
}
}
THis
Civil 3D Certified Professional
Solved! Go to Solution.