Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to use CanPlaceElementType() method

Anonymous

How to use CanPlaceElementType() method

Anonymous
Not applicable

Can someone tell me what's wrong with my code. I am able to build it but failed to run. See images :- 

 

UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
ElementType etype = doc.GetElement(new ElementId(BuiltInCategory.OST_Walls)) as ElementType;
TaskDialog.Show("HKS",uidoc.CanPlaceElementType(etype).ToString());

 

1.PNG2.PNG

0 Likes
Reply
Accepted solutions (1)
411 Views
2 Replies
Replies (2)

Anonymous
Not applicable

I think the problem lies in the:

ElementType etype = doc.GetElement(new ElementId(BuiltInCategory.OST_Walls)) as ElementType; (is null)

 

The Id you're trying to get is of a Category. For the ElementType I believe you need to be specific of a type (i.e. a specific Wall or Wall Type), not a whole category (i.e. Walls). 

 

 

0 Likes

FAIR59
Advisor
Advisor
Accepted solution

you can use document.GetDefaultElementTypeId()  to get a default elementtype for the document.

 

			ElementType etype =doc.GetElement( doc.GetDefaultElementTypeId(ElementTypeGroup.WallType)) as ElementType;
			TaskDialog.Show("HKS",string.Format("can place elementtype {0}: {1}",etype, uidoc.CanPlaceElementType(etype).ToString()));