Problems with SetDefaultFamilyTypeId and PostableCommands

Problems with SetDefaultFamilyTypeId and PostableCommands

MvL_WAG
Contributor Contributor
1,576 Views
16 Replies
Message 1 of 17

Problems with SetDefaultFamilyTypeId and PostableCommands

MvL_WAG
Contributor
Contributor

Hello Everybody, 

 

I'm trying to create a command that sets the default Familytype before using a postablecommand to create an actual element.

 

Default Revit uses the last place type when starting a command again.

The user has to manualy find the desired type to place in the view.

 

I have got the same kind of logic working with a TextNote.

 

So, when the user uses my command, 

the defaultTextNotetype of the project is Set to the textnotetype i want and then the Text Command is activated with the postablecommand methods. This works like a charm. the code below, changes the textnotetype to a specific type and the user gets to place a text in the desiderd type. (in this case the third found in the collector).

So it doesn't matter what text type was last used to

//Get 3 textnotetype from collector 
Element el = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).ToElements()[3];      
if (doc.IsDefaultElementTypeIdValid(ElementTypeGroup.TextNoteType, el.Id))
{
    TaskDialog.Show("Revit", "Valid Type");
    Transaction trans = new Transaction(doc, "SetDefaultTextNoteType");
    trans.Start();
    doc.SetDefaultElementTypeId(ElementTypeGroup.TextNoteType, el.Id);
    trans.Commit();
}
else
{
	TaskDialog.Show("Revit", "Invalid Type");
}
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Text);
app.PostCommand(id);           

 

But when I try to adapt this command to use the SetDefaultFamilyTypeId() the changes of type isn't reflected in the command when it is activated using postablecommand

 

This is the code i got so far:

The dialog boxes tell me the default type Id of the category is changed. 

But this type isn't used in the posted command, or even when activating the command itself afterwards.

//Pick a symbol to set as default type
FamilyInstance Pick = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element).ElementId) as FamilyInstance;
FamilySymbol el = Pick.Symbol;
ElementId catId = new ElementId(BuiltInCategory.OST_DetailComponents);
if (doc.IsDefaultFamilyTypeIdValid(catId, el.Id))
{
	TaskDialog.Show("Revit", "Valid Type");
	Transaction trans = new Transaction(doc, "SetDefaultFamilyType");
	trans.Start();
	doc.SetDefaultFamilyTypeId(catId, el.Id);
	trans.Commit();
}
else
{
	TaskDialog.Show("Revit", "Invalid Type");
}
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.DetailComponent);
app.PostCommand(id);

 

Does anybody know what I am doing wrong?

 

Maarten

0 Likes
1,577 Views
16 Replies
Replies (16)
Message 2 of 17

RPTHOMAS108
Mentor
Mentor

Nothing you've done seems particularly wrong to me. I've never used this 'default type' feature but it is advertised to work as you've done (no caveats suggesting otherwise).

0 Likes
Message 3 of 17

joshua.lumley
Advocate
Advocate

System families use SetDefaultElementTypeId not SetDefaultFamilyTypeId.  

 

ElementType myElementType = doc.GetElement(myElement.GetTypeId()) as ElementType;
foreach(ElementTypeGroup myElementTypeGroup in Enum.GetValues(typeof(ElementTypeGroup))) //finds and sets the default for system families
{
	if (myElementTypeGroup.ToString() == myElementType.GetType().Name) {
		doc.SetDefaultElementTypeId(myElementTypeGroup, myElement.GetTypeId());
	}
}

 

0 Likes
Message 4 of 17

MvL_WAG
Contributor
Contributor

Thanks for the reactions,

 

I actually aren't trying to set it for Systemfamilies but for loadable components.

(Mainly Detail Items, Generic Annotations and TagTypes).

 

But I can't get that to work like I mentioned before.

0 Likes
Message 5 of 17

jeremy_tammik
Alumni
Alumni

It looks OK to me too.

 

Can you create a minimal reproducible case for this that still fails reliably to share with the development team for analysis?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 17

MvL_WAG
Contributor
Contributor

Hello Jeremy,

 

I have attached a test project in which I would like to place the detail component di_truck_VAZ.

 

When i run the code below. the type i am trying to set is valid, and is set. but the postable command uses another familytype (WAG_CoordinatenSnap)

 

I have also attachted a video of the problem

I hope this is enough as input for the development team

public class Script
{
	private static Document doc;
	public static Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		//Stopwatch t.b.v Diagnostics
		Stopwatch sw = new Stopwatch();
		sw.Start();

		//Variabelen.
		Autodesk.Revit.UI.UIApplication app = commandData.Application;
		Autodesk.Revit.ApplicationServices.Application application = app.Application;
		UIDocument uidoc = commandData.Application.ActiveUIDocument;
		doc = uidoc.Document;
		Selection selection = uidoc.Selection;
	   
		FamilySymbol fs = GetSymbol("di_truck_VAZ", "di_truck_VAZ");
		ElementId catId = new ElementId(BuiltInCategory.OST_DetailComponents);           

		
		if (doc.IsDefaultFamilyTypeIdValid(catId, fs.Id))
		{
			TaskDialog.Show("Revit", fs.Name + " is a valid Type to be set as default");
			Transaction trans = new Transaction(doc, "SetDefaultFamilyType");
			trans.Start();
			doc.SetDefaultFamilyTypeId(catId, fs.Id);
			trans.Commit();
		}
		else
		{
			TaskDialog.Show("Revit", "Invalid Type");
		}

		TaskDialog.Show("Revit", "The default family type is set to " + doc.GetElement(doc.GetDefaultFamilyTypeId(catId)).Name);

		RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.DetailComponent);
		app.PostCommand(id);

		sw.Stop();
		sw.Elapsed.ToString();

		TaskDialog td = new TaskDialog("Revit");
		td.MainInstruction = "Einde MvL Script";
		td.MainContent = "Runtime: " + sw.Elapsed.ToString();

		//td.Show();
		Autodesk.Revit.UI.Result result = Result.Succeeded;
		return result;
	}

	/// <summary>
	/// GetFamilySymbol By name and type
	/// </summary>
	/// <param name="familyName"></param>
	/// <param name="symbolName"></param>
	/// <returns></returns>
	public static FamilySymbol GetSymbol(string familyName, string symbolName)
	{
		return new FilteredElementCollector(doc).OfClass(typeof(Family)).OfType<Family>().FirstOrDefault(f => f.Name.Equals(familyName))?.GetFamilySymbolIds().Select(id => doc.GetElement(id)).OfType<FamilySymbol>().FirstOrDefault(symbol => symbol.Name.Equals(symbolName));
	}

}

 

 

0 Likes
Message 7 of 17

jeremy_tammik
Alumni
Alumni

Dear Maarten,

 

Thank you for your report and clear reproducible case.

 

I logged the issue REVIT-173976 [SetDefaultFamilyTypeId has no effect] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 17

MvL_WAG
Contributor
Contributor

Hello Jeremy,

 

Thanks for creating the Issue,

 

I am a bit new to this Issues thing.

 

Where can I actually find those issues listed?

And how can I contact the development team?

 

Thanks

0 Likes
Message 9 of 17

jeremy_tammik
Alumni
Alumni

I wish you could look at the issues yourself and contact them directly.

 

Unfortunately, that is not so.

 

Write a message here, quote the ticket number and hope for the best is all you can do...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 17

MvL_WAG
Contributor
Contributor
Aha Okay, I thought I was missing something!
Thanks for the help and the quick responses!
0 Likes
Message 11 of 17

jeremy_tammik
Alumni
Alumni

My pleasure entirely 

  

🙂

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 12 of 17

MvL_WAG
Contributor
Contributor

For future reference,

 

I have had a new insight for my problem.

I have come up with a workaround, at least for the Detailcomponents 

Instead of using a postable command to place a familyinstance.

 

I use the uidoc.PromptForFamilyInstancePlacement() method.

This way the goal of my application is achieved (at least patially). 

 

0 Likes
Message 13 of 17

jeremy_tammik
Alumni
Alumni

Glad to hear that!

 

Why only partially?

   

Would NewFamilyInstance also work?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 14 of 17

MvL_WAG
Contributor
Contributor

Ehm,

 

To use NewFamilyInstance every has to be defined in the command it self.

I want the user experience to be the same as the normal revit command.

 

So for instance it it posible to make a form with a textbox and let the user insert a string,

then let the user pick a point where the is supposed to go. the add it using the NewTextNoteType.

 

But that has other downfalls, no preview while picking leader end points, no preview of typed text etc.

Same for placing families. when using the promptforFamily, the user experiences the same thing as he used a OOTB command. 

 

And the bennefits of the preview of the element to be placed, and for rotating the instance with spacebar. 

 

My main goal is to use the OOTB stuff if it is better than something i would code myself.

Why recreate something that doesn't work as wel as the original.

 

The sollution for my case is only partial at the moment because i don't know if also can use it for generic annotatians and tags.

 

But maybe the PostRequestForElementTypePlacement() can help with that.

0 Likes
Message 15 of 17

jeremy_tammik
Alumni
Alumni

Yes, of course. Thank you for explaining and sorry for the silly question.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 16 of 17

MvL_WAG
Contributor
Contributor

No such thing as a silly question!

0 Likes
Message 17 of 17

jeremy_tammik
Alumni
Alumni

Dear Maarten,

 

Thank you for your patience with this.

 

The development team analysed the issue REVIT-173976 [SetDefaultFamilyTypeId has no effect] and determined that a modification to our software is required.

 

They created a new ticket REVIT-175004 [SetDefaultFamilyTypeId has no effect] for this work. Please make a note of this number for future reference.

 

Cheers,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes