0% found this document useful (0 votes)
11 views3 pages

Remove Extra Annotation Scales in AutoCAD

Delete anotation

Uploaded by

bravomikeparle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Remove Extra Annotation Scales in AutoCAD

Delete anotation

Uploaded by

bravomikeparle
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using [Link].

ApplicationServices;
using [Link];
using [Link];
using [Link];

namespace AnnotationScaling
{
public class Commands
{
[CommandMethod(
"AIOBJECTSCALEREMOVEOTHERS",
([Link] | [Link])
)]
static public void RemoveAllButCurrentScale()
{
Document doc =
[Link];
Database db = [Link];
Editor ed = [Link];

// Get the manager object and the list of scales

ObjectContextManager ocm = [Link];


ObjectContextCollection occ =
[Link]("ACDB_ANNOTATIONSCALES");

// Prompt the user for objects to process (or get them


// from the pickfirst set)

PromptSelectionOptions pso = new PromptSelectionOptions();


[Link] = "\nSelect annotative objects";
PromptSelectionResult psr = [Link](pso);
if ([Link] != [Link])
return;

// Maintain counters of objects modified and scales removed

int objCount = 0, scaCount = 0;

// Use a flag to check when we first modify an object

bool scalesRemovedForObject = false;

Transaction tr =
[Link]();
using (tr)
{
// If we can't find the current annotation scale in our
// dictionary, we have a problem

if (![Link]([Link]))
{
[Link](
"\nCannot find current annotation scale."
);
return;
}

// Get the ObjectContext associated with the current


// annotation scale

ObjectContext curCtxt =
[Link]([Link]);

// Check each selected object

foreach (SelectedObject so in [Link])


{
// Open it for read

ObjectId id = [Link];
DBObject obj = [Link](id, [Link]);

// Check it's annotative and has the current scale

if ([Link] == [Link] &&


[Link](curCtxt)
)
{
// Now we get it for write

[Link]();

// Loop through the various annotation scales in


// the drawing

foreach (ObjectContext oc in occ)


{
// If it's on the object but not current
// (for some reason we have to check the name
// rather than oc == curCtxt)

if ([Link](oc) &&
[Link] != [Link]
)
{
// Remove it and increment our counter/set our
// flag

[Link](oc);
scaCount++;
scalesRemovedForObject = true;
}
}

// Increment our counter for objects once per pass


// and then reset the flag

if (scalesRemovedForObject)
{
objCount++;
scalesRemovedForObject = false;
}
}
}
[Link]();

// Report the results


[Link](
"\n{0} scales removed from {1} objects.",
scaCount, objCount
);
}
}
}
}

Common questions

Powered by AI

Transactions are used within the 'RemoveAllButCurrentScale' method to manage the sequence of operations performed on the database objects in a safe and consistent manner. Enclosing operations within a transaction ensures that changes are only committed if all operations complete successfully, thereby providing error handling and rollback capabilities to maintain database integrity. If any error occurs, the transaction can be discontinued without affecting the drawing file .

The code snippet provides feedback to the user by writing a message to the AutoCAD editor at the end of the transaction. The message includes the number of scales removed and the number of objects from which scales were removed ( '{0} scales removed from {1} objects.'). This output allows the user to verify what changes were made during the execution of the command .

If the current annotation scale is not found in the document's context collection, the code writes a message to the editor output stating that it cannot find the current annotation scale ('Cannot find current annotation scale.') and subsequently returns without making any changes. This effectively acts as an early exit condition to prevent further execution .

Before an object is modified within the 'RemoveAllButCurrentScale' method, it must meet two primary conditions: it should be annotative ('obj.Annotative == AnnotativeStates.True') and it should contain the current annotation scale ('obj.HasContext(curCtxt)'). These conditions ensure that only relevant objects are modified, preventing unintended scale removals from non-annotative or improperly scaled objects .

In the context of the AutoCAD code, 'UpgradeOpen' is invoked on objects initially opened in read mode that need to be modified, upgrading their access level to write mode. This is crucial for operations such as removing annotation contexts because write permission is required to make changes to an object. Using 'UpgradeOpen' ensures that the transaction can safely alter object properties without initially compromising performance or locking issues by opening all objects in write mode upfront .

The code handles the initial selection of objects by using the PromptSelectionOptions class to present a prompt message ('Select annotative objects') to the user. The PromptSelectionResult returned by the 'ed.GetSelection(pso)' method call is then checked to ensure a successful status, signifying that the user has selected objects to process. If the selection is successful, it proceeds to iterate over these objects; otherwise, the process terminates without further action .

The potential problem addressed by checking the existence of the current annotation scale context in the database dictionary is the scenario where the expected scale does not exist, indicating a possible misconfiguration or corruption in the drawing. Avoiding modification in such cases prevents misapplication of scale removals and preserves the integrity of object annotations. This check serves as a crucial validation step before engaging in scale modification operations .

The code determines that annotation scales need to be removed from an object by iterating through the context collection of scales and checking if each scale is applied to the object but is not the current scale ('oc.Name != db.Cannoscale.Name'). If both conditions are met, the scale is removed from the object using 'obj.RemoveContext(oc)', and a counter is incremented to reflect scales removed and objects modified .

The code ensures that only annotative objects with the current annotation scale are processed by first checking if each object is annotative using 'obj.Annotative == AnnotativeStates.True' and then verifying if the object has the current annotation scale context using 'obj.HasContext(curCtxt)'. Only objects meeting both conditions are opened for modification and have their non-current scales removed .

The 'RemoveAllButCurrentScale' method is designed to remove all annotation scales from annotative objects in an AutoCAD drawing, except for the current annotation scale. This method prompts the user to select annotative objects and then iterates through each object to ensure only the current scale remains, removing any other scales present. It keeps track of the number of scales removed and objects modified, providing a summary to the user upon completion .

You might also like