« Selecting Model Elements | Main | Imports in Families »

May 22, 2009

Comments

It was next on my agenda: to make my first revit api program. Now this posts makes me really worried, do i really need to rewrite it every year. That does not sound good.

Dear Priit,

Glad to hear you are interested in getting started with the Revit API. Fact is, the API can change a little bit from release to release, but that should not be a cause for too much concern. Only small changes are made to the API from one release to the next. If you are not making any use of API functionality that changed, your add-in may run unmodified on several releases of Revit. It is however recommended to recompile fresh for each release. Mostly, this requires no or only very changes.

In this specific case, the addition of the new family API is an extremely big step forward for Revit programming, and it would have been surprising if it had not affected anything at all.

One command out of thirty-two in The Building Coder samples was affected by this change, and even the update required for that change was very small. Thirty-one of the thirty-two were not affected in any significant way, and twenty-seven out of the thirty-two commands were not affected at all.

Eight lines of code out of a total of 15.000 needed editing.

Feedback from large application developers indicates that porting even the most complex of applications requires no more than a few hours.

Cheers, Jeremy.

Hello,

I sympathize with what you had to go through. My primary occupation is programming using Visual Studio. On certain occasions, I have had to upgrade solutions to newer versions of VS to add functionality that the older version did not have. Sadly, the VS "conversion wizard" can be very buggy, and on one occasion I was so stumped I had to open an MS ticket to get help because I couldn't figure out how to manually adjust the converted files so the projects would compile.

I think MS needs to thoroughly test the conversion wizard against against specific legacy versions of VS before allowing the wizard to run (for as of yet untested scenarios, the system should pop a dialog saying that conversion can't take place right now, but may be possible later as patches from Windows Update are issued).

Jeremy,

Sorry to dig this up, but how does one accomplish the equivalent of Family.LoadedSymbols within the context of the family's parent document? I'll do my best to explain.

For example, try manipulating the weld symbol:

If you use the EditFamily() method to enumerate through the family to retrieve the "Fillet" symbol the elementId will be (for example) 1000.

Using RvtMgdDbg if one snoops the weld family once loaded in a project you can see that the "Fillet" symbol is given an Id of (say) 800000.

So my question: How do you retrieve the loaded symbol's Id in the context of the parent document, not the family editor itself?

Dear Chris,

Filter or iterate the elements of whatever document it is that you need the element id in, identify the symbol you are looking for, and Bob's your uncle.

Cheers, Jeremy.

Try as I might I'm still not having success finding the family's symbols in the parent document. For instance, I simply load up a new project (default structural template), drag in a weld symbol, select it, and run through the following code (I've trimmed the easy obvious parts):

foreach (Element elem in selection)
{
List weldSymbolList = new List();

Parameter botSymbol = elem.get_Parameter("Bottom Symbol");
ElementId botSymId = botSymbol.AsElementId();
Element tester = revitDoc.get_Element(ref botSymId);

AnnotationSymbol elementAS = elem as AnnotationSymbol;
FamilyInstance elementFI = elementAS.AsFamilyInstance;
Family fam = elementFI.Symbol.Family;
Document familyDoc = revitDoc.EditFamily(fam);

if (familyDoc != null && familyDoc.IsFamilyDocument == true)
{
ElementIterator itrFS = familyDoc.get_Elements(typeof(AnnotationSymbolType));
itrFS.Reset();
while (itrFS.MoveNext())
{
Element eleFam = itrFS.Current as Element;
if (eleFam != null)
{
weldSymbolList.Add(eleFam.Name);
}
}

ElementIterator itrParentDoc = revitDoc.Elements;
itrParentDoc.Reset();
while (itrParentDoc.MoveNext())
{
Element eleDoc= itrParentDoc.Current as Element;
if (eleDoc != null)
{
if (weldSymbolList.IndexOf(eleDoc.Name) != -1)
MessageBox.Show("Found " + eleDoc.Name + " : " + eleDoc.Id.Value);
}
}
}

And the weld symbols are never found in the iteration. What may I be missing? Your help is much appreciated!

Dear Chris,

I still have a hard time understanding what your difficulty is.

Maybe there is a misunderstanding here. Maybe it is just too simple. Maybe the term 'parent' document is causing confusion.

Does the following correctly describe your need?

1. Create a new project document.

2. Load a family document into the project document.

3. Determine the element ids of the family symbols in the project document context.

If so, then the Revit API Introduction lab Lab3_1_StandardFamiliesAndTypes does exactly what you need.

Cheers, Jeremy.

Hi Jeremy,

From your answer, is it meant that we can load mass into curent project via revit API? I have search a correct function but seem it failed.
What I meant is:
1. create new project document
2. using revit api
i. retrieve selected mass family
ii.load into new project into selected level
iii.show in new project document


Thank you.

Dear Abby,

I do not think you can load a mass directly into the current project, but if you have packaged it as a family I see no reason why it should not be possible to load it.

Any standard family can be loaded into Revit, and instances of its symbols inserted into and displayed in the current project.

Cheers, Jeremy.

Hi Jeremy.

Thank you for your reply. I managed to load mass into current project by package it as family.
What i have done is:
1. Create new project
2. In Revit API,
i. it will check whether current document is family.
ii. if not family, it shall create new family.
iii. then i'll create new mass and save it.
iv. then i load new created family into current document.

It seem ok and what i need is to view mass manually since it doesn't shows in floor plan.
Is is correct or there are better way to do that?

Thank you.

Dear Abby,

That sounds fine to me.

Cheers, Jeremy.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)

Jeremy Tammik

AboutTopicsIndexSource