How do I a selected legendcomponent in the open EditFamily ?

How do I a selected legendcomponent in the open EditFamily ?

a180401ta
Participant Participant
571 Views
4 Replies
Message 1 of 5

How do I a selected legendcomponent in the open EditFamily ?

a180401ta
Participant
Participant

Hi All,


I tried the following articles but I didn't get results.

 

https://thebuildingcoder.typepad.com/blog/2014/09/modifying-saving-and-reloading-families.html
https://forum.dynamobim.com/t/setting-the-builtin-parameter-accessible-thru-the-family-editor/10554/...
https://forums.autodesk.com/t5/revit-api-forum/how-to-dismiss-popups-when-going-into-quot-editfamily...

 

Code segment:
.....
family = UnwrapElement(IN[0])
en = family[0]
famdoc = doc.EditFamily(en.Family)
.....

 

What is the problem?
How do we fix this?
Any assistance is much appreciated.

 

 

QQ190508.jpg

0 Likes
Accepted solutions (1)
572 Views
4 Replies
Replies (4)
Message 2 of 5

FAIR59
Advisor
Advisor

The ElementId of the ElementType / FamilySymbol of the legendcomponent is stored in the BuiltInParameter..LEGEND_COMPONENT.

 

From the FamilySymbol you find the Family to Edit. In c# code:

// Document document;
// Element legendelement;
Parameter p = legendelement.get_Parameter(BuiltInParameter.LEGEND_COMPONENT);
if (p==null) return;
            
FamilySymbol symb = document.GetElement(p.AsElementId()) as FamilySymbol;
if (symb==null) return;
            
Family fam = symb.Family;
if(fam.IsEditable)
{
     Document d = document.EditFamily(fam);
}
Message 3 of 5

a180401ta
Participant
Participant

Thank you for your reply.

But there is still no way to finish opening the "Edit Family" editor.

cap1902_00807.jpg

Current operation process Video:
https://youtu.be/-nfDuS8Nl2w

 

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Cs18_TestEditFamily : IExternalCommand
{

    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Document doc = uidoc.Document;

    Autodesk.Revit.DB.View view = uidoc.ActiveView;
    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;

    Reference r;
    r = uidoc.Selection.PickObject(ObjectType.Element, "Selection Element");
    var elem = doc.GetElement(r.ElementId);

    Parameter p = elem.get_Parameter(BuiltInParameter.LEGEND_COMPONENT);
    if (p == null) { MessageBox.Show("Selection null"); }
    FamilySymbol symb = doc.GetElement(p.AsElementId()) as FamilySymbol;
    if (symb == null) { MessageBox.Show("Selection null"); }
    Family fam = symb.Family;
    if (fam.IsEditable)
    {
        MessageBox.Show("True");
        Document d = doc.EditFamily(fam);
    }
    return Result.Succeeded;
}
}

 

 


My English is pretty limited, please don't mind.


How do we fix this?

 

Any assistance is much appreciated.

0 Likes
Message 4 of 5

FAIR59
Advisor
Advisor
Accepted solution

With the call to Document.EditFamily(), the family opens in the background.

 

To open the family like  pressing the [Edit Family] button, add this code.

 

//Document d = document.EditFamily(fam);

IEnumerable<ViewPlan> plans = new FilteredElementCollector(d)
					.OfClass(typeof(ViewPlan))
					.Cast<ViewPlan>()
					.Where( vp=>!vp.IsTemplate);
ViewPlan v = plans.FirstOrDefault();
if (v==null) return;
UIDocument uidoc = new UIDocument(d);
IEnumerable<ElementId> ids = new FilteredElementCollector(d,v.Id)
				.ToElementIds();
uidoc.Application.DialogBoxShowing+= ThisApplication_DialogBoxShowing; uidoc.ShowElements(ids.ToList()); uidoc.Application.DialogBoxShowing-= ThisApplication_DialogBoxShowing;
internal void ThisApplication_DialogBoxShowing(object sender, DialogBoxShowingEventArgs e)
{
	e.OverrideResult((int) TaskDialogResult.Ok);
}

 

Message 5 of 5

a180401ta
Participant
Participant

Thanks FAIR59.
But, not yet completed.

keep it up.

0 Likes