Placing a generic annotation on a legend or drafting view

Placing a generic annotation on a legend or drafting view

stever66
Advisor Advisor
3,993 Views
3 Replies
Message 1 of 4

Placing a generic annotation on a legend or drafting view

stever66
Advisor
Advisor

Would anyone care to share a code example that places a generic annotation on either a legend or drafting view?

I've searched and searched, and I can't find an example anywhere.

From the changes and additions, I see that:

Document.Create.NewAnnotationSymbol(point, ann_type, doc.ActiveView);

is now obsolete, but there is no mention of any replacement keyword.   I assume I now have to use the more generic : 

NewFamilyInstance  

 

But I'm not sure which overload to use:

NewFamilyInstance Method (XYZ, FamilySymbol, StructuralType)  or

NewFamilyInstance Method (XYZ, FamilySymbol, View)

 

For the first overload, I'm not sure what to do with the structuraltype variable.

With the second overload, how do I set the view?  I already have the view open.

 

Thanks in advance.

Accepted solutions (1)
3,994 Views
3 Replies
Replies (3)
Message 2 of 4

stever66
Advisor
Advisor
Accepted solution

Well, I really didn't think I could get this to work without an example, but the first overload does work.  I'm not sure why it takes an XYZ point since the views are 2D, and there is no Z elevation.  I just set the Z to zero.  (Setting the Z higher seems to offset the Y value by a little, but always by the same amount?  No idea why.)

 

I couldn't get the overload with the StructuralType to work.  I keep getting an error saying I'm trying to access that variable outside its protection level.  The contextual help also seems to indicate I should have a "level" variable before the structural type.  I tried adding that, but still got the same error.

 

Anyhow, the code I got to work:

public void NewLegend()
        {
            UIDocument uiDoc = this.ActiveUIDocument;   //dont need this
            //Use the Application keyword to access the application object.
            Document doc = this.ActiveUIDocument.Document;
            
             using (Transaction t = new Transaction(doc))
             {
                 XYZ MyPoint =new XYZ (5.0,5.0,0);
                
                 
                 FilteredElementCollector familyCollector = new FilteredElementCollector(doc);
                familyCollector.OfClass(typeof(FamilySymbol));
                FamilySymbol familySymbolToFind = null;
                foreach (FamilySymbol familySymbol in familyCollector)

                    {
                                        
                    if (familySymbol.Name == "DATA" && familySymbol.Family.Name == "DATA")
                    {
                            familySymbolToFind = familySymbol;
                            TaskDialog.Show("Revit""Found the family symbol");
                    }
                      

                    }// end foreach
        
                View currentView = this.ActiveUIDocument.ActiveView;


                t.Start("Place Symbol");
                FamilyInstance instance = doc.Create.NewFamilyInstance (MyPoint, familySymbolToFind, currentView);
                
                //FamilyInstance instance = doc.Create.NewFamilyInstance (MyPoint, familySymbolToFind , StructuralType.NonStructural);  // couldnt get this one to work?
                
                t.Commit();
             }

 

 

Message 3 of 4

marcusss_
Enthusiast
Enthusiast

hey there,  appreciate this post.

I tried to use doc. Create.NewFamilyInstance (XYZ, FamilySymbol, View) to place an AnnotationSymbol and I get 

TypeError: expected FamilySymbol, got AnnotationSymbol

 

any insight by chance? I can't find any methods for creating a new annotation instance.   thanks.

0 Likes
Message 4 of 4

stever66
Advisor
Advisor

I don’t know offhand.  Maybe if you post the  code you are using to get the family symbol.  

0 Likes