Here is a short and sweet deletion question handled by Joe Ye:
Question: I am trying to delete a GraphicStyle object in a RFA family document.
I tried to achieve this using the following code, but it was not successful:
Dim elem As Element = m_rvtDoc.Element( "5ad9f0cf-6eff-4c63-8a44-9f3a87881dd7-00000b22") m_rvtDoc.Delete(elem)
How can I delete this object?
Answer: Some internal line style objects cannot be deleted, because the model requires their presence. As you can see in the following image, the Delete and Rename buttons are disabled when Hidden Lines are selected:
Some of the other line types, i.e. GraphicStyle objects, can very well be deleted.
I manually created an own line type in the dialogue shown above. Since it is my own, the model does not depend on it. I can then delete the line type I created using the following external command:
[TransactionAttribute( TransactionMode.Manual )] public class Command : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string messages, ElementSet elements ) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Transaction trans = new Transaction( doc ); trans.Start( "Delete Line Style" ); //ElementId id = new ElementId( 4889 ); //Element elem = doc.get_Element( id ); string guid = "6387d73b-1e94-456a-8804" + "-aaaf48a905f0-0000131a"; Element elem = doc.get_Element( guid ); doc.Delete( elem ); trans.Commit(); return Result.Succeeded; } }
By the way, deleting elements obviously requires an open transaction, which needs to be committed after the deletion.
Is there anyway to create a line style and Line Pattern with the API in 2013?
Posted by: Matt | October 24, 2012 at 21:26
How can one determine the guid of an object style? I want to be able to at least delete object styles. It would even be better if I knew how to rename them. I'd appreciate the help.
Posted by: Wim Tas | October 28, 2012 at 18:57
Dear Matt,
Have you looked at the LinePattern class?
There is a LinePatternElement.Create method...
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 31, 2012 at 05:04
Dear Wim,
The GUID of an object style is returned by the standard Element.UniqueId property.
How to delete an object style is demonstrated above.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 01, 2012 at 11:08
Dear Matt,
Maybe there is something of use in here?
http://forums.autodesk.com/t5/Autodesk-Revit-API/Create-Line-Pattern-Type/td-p/3666094
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 01, 2012 at 11:18
Is renaming possible?
Posted by: Wim Tas | November 03, 2012 at 17:53