How to get project from a family in revit 2014

How to get project from a family in revit 2014

Anonymous
Not applicable
622 Views
8 Replies
Message 1 of 9

How to get project from a family in revit 2014

Anonymous
Not applicable

Hi,

 

Is there any way to get a project document from the family document.

 

I think we can get families from a project document but is reverse possible.

 

I think there is no any api which will directly give me a project document from a family which is going to get edited.

 

Your help will be appreciated.

 

Thanks,

Vinod

0 Likes
623 Views
8 Replies
Replies (8)
Message 2 of 9

matthew_taylor
Advisor
Advisor

Hi Vinod,

You could access the DocumentSet, and use a filteredElementCollector on each of those documents (if they are models) to see if the family exists in them.

You may turn up more than one result. The documentSet is probably in order, so you may be able to infer the model that you are after.

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi Matt,

 

Thanks for your help,i have implemented it in  the same way as you said.

 

So  when we edit family, document before this in the document set is the document in which family which is going to get edited is loaded.

 

Is there any other property on the family which I can use on family(on which I run edit family) and the families which are loaded in the project so I will be very sure that last document before this family is the same document from which I am editing it.

 

I am trying as follows but it does not work.

 

public Document GetProjectOfTheLoadedFamily(Family familyDoc)
{
Document projectDoucment = null;
var openedDocs = mRevitContext.RevitApp.Documents;
var projectIterator = openedDocs.ForwardIterator();

while (projectIterator.MoveNext())
{
var currentDoc = projectIterator.Current as Document;

if (currentDoc.IsFamilyDocument)
continue;

IList<Element> families = new FilteredElementCollector(currentDoc).OfClass(typeof(Family)).ToElements();
foreach (Family family in families)
{
if (family != null)
{
if (family.Id.Compare(familyDoc.Id) == 0)
{
projectDoucment = currentDoc;
break;
}

if (family.Name.Equals(familyDoc.Name))
{
projectDoucment = currentDoc;
break;
}
}
}
}
return projectDoucment;
}

 

 

Thanks for your help.

 

Vinod

 

0 Likes
Message 4 of 9

matthew_taylor
Advisor
Advisor

Hi Vinod,

I've had another look at it, and you should be able to use an event (or combination of events) to track this. Check out the EventsMonitor sample in the SDK.

 

(BTW, your code is faulty, as the family document will be an actual DB.Document, not a DB.Family, but that won't matter if the above suggestion works.) If you want to persevere with the first idea, you'll need to use a name comparison similar to what you have shown, but the family document won't have an Id.)

 

By the way, this could get very complex, coping with save-as and that sort of thing.

Also, I don't recommend opening families from within a project if it can be avoided. Revit re-creates lots of garbage in the family, such as line patterns, fill patterns, and materials.

 

If you still want to go down this path, you may find it easier to redefine the relevant commands than to work around them (especially for something as simple as opening a family document).

Jeremy provides a link here: http://forums.autodesk.com/t5/revit-api-forum/disable-or-overwrite-quot-editing-request-quot-for-wor...

 

Sorry Vinod, I started rambling a bit. I hope this guides you forward!

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 5 of 9

Anonymous
Not applicable

Hi Matt,

 

Thanks for your reply.

 

I have tried with the command binding approach also but I have observed following problems in it

 

1.There are total three commands which can be used for editing family

 

EDit family from the contextual m,enu

Edit from the right click on the type of the family

and from the ribbon item which gets enbaled when we select family instance in the viewer.

 

So I could bind two commands 1 and 2 but could not bind the third command from the ribbon item.

 

Id of this command is "Dialog_Revit_EditLoadedFamilyDbar:Control_Revit_EditLoadedFam".

 

is there any other way to bind this item or event where I can know before executing this event.

 

Thanks,

Vinod

0 Likes
Message 6 of 9

matthew_taylor
Advisor
Advisor

Hi Vinod,

No problem.

 

You may want to check if the double-click of a family triggers one of those 3 commandIds.

 

The journal shows the ID for select instance and click 'edit family' on the ribbon as Dialog_Revit_EditLoadedFamilyDbar (in Revit 2017).

Have you tried that?

 

Cheers,

 

-Matt

 

[edited typo....it's best not to 'lick' edit families.]


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi Matt,

 

Yes I have tried with this command Id Dialog_Revit_EditLoadedFamilyDbar:Control_Revit_EditLoadedFam"which is the Id of the eidt family

in the ribbon but this returns null when we call RevitCommandId.LookupCommandId for this Id .

 

I have tried this in the Item Initialized  event of the component manager  and in the start up of the external application.

 

Thanks,

Vinod

 

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

Hi Matt,

 

Sorry for the last reply,yes we can bind the  command "Dialog_Revit_EditLoadedFamilyDba".I have tried this in the startup of the extrenal application

and registered a before executed event but this does not trigger the event where as I can get the event for the command 1 and 2.

 

Any help?

 

Thanks,

Vinod

0 Likes
Message 9 of 9

matthew_taylor
Advisor
Advisor

Hi Vinod,

Did you subscribe to the AddInCommandBinding event (as shown in an example in the SDK)?

 

It appears that the sender of the DisableEvent (in the example) is the UiApplication object, so you can get the selection from there (your family), and implement your own 'open family document' once you've added the family name and document to a dictionary (or something) for later use.

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes