How to create an element that belongs to a custom sub category?

How to create an element that belongs to a custom sub category?

aryan4WGLU
Participant Participant
870 Views
5 Replies
Message 1 of 6

How to create an element that belongs to a custom sub category?

aryan4WGLU
Participant
Participant

I'd like to create a new custom element with custom geometry in Reivt that belongs to a custom sub category. 

 

What I have done so far is: 

  1. I have created a new Subcategory using NewSubcategory Method (revitapidocs.com)
Categories categories = doc.Settings.Categories;
Category siteCategory = categories.get_Item(BuiltInCategory.OST_Site);
Category customCategory = categories.NewSubcategory(siteCategory, "MY COORDINATES");
doc.Regenerate();

 

      2. I have tried creating a new DetailCurve using NewDetailCurve Method (revitapidocs.com)

double radius = 10.0;
// Create the circle
Curve circle = Arc.Create(new XYZ(10, 10, 0), 10.0, 0.0, 2.0 * Math.PI, XYZ.BasisX, XYZ.BasisY);
// Create a new detail detailCurve element
DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, circle) as DetailCurve;

 

However I can't figure out how to assign my new `DetailCurve` to my `customCategory` created earlier. Is there a way to do this?

 

My final goal is to be able to create a custom object that its visibility is dependent on my custom category so the user can toggle this from Visibility/Graphics Overrides settings. Is there a better way to do this? 

0 Likes
Accepted solutions (2)
871 Views
5 Replies
Replies (5)
Message 2 of 6

moturi.magati.george
Autodesk
Autodesk

Hi @aryan4WGLU,

 

You can try something like this. I have not tested it myself but it should guide you in achieving what you want.

 

// get the category to create the subcategory in
Category lineCat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

// create a new subcategory
Subcategory customCategory = lineCat.SubCategories.NewSubcategory("MY COORDINATES");
doc.Regenerate();

// create a new DetailCurve object
DetailCurve detailCurve = .....

// assign the subcategory to the DetailCurve
detailCurve.Subcategory = customCategory;

 

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 3 of 6

TripleM-Dev.net
Advisor
Advisor

Hi @aryan4WGLU,

 

Detail/ModelLine's subcategories are their Styles, you're creating subcategories under the Site Category.

As @moturi.magati.george states create SubCategories under the Lines Category (= BuiltInCategory.OST_Lines)

 

Retrieve the valid styles from the DetailCurve created using: GetLineStyleIds Method, from these chose one (evaluate their name for the correct one)

Apply that style to the created DetailCurve LineStyle Property 

 

Retrieving the valid linestyles first is important because the Lines Category also contains styles that can't be used on DetailCurves like RoomBoundary lines, Invisible Lines etc.

 

- Michel

Message 4 of 6

aryan4WGLU
Participant
Participant

Hi @TripleM-Dev.net @moturi.magati.george

 

Thank you for getting back to me! 

 

I understand that Detail/ModelLine's subcategories are their styles however that is not what I'm interested in. 

 

My goal is to create an element that is assigned to my custom Subcategory created under Site (`OST_SITE`). So in short, I'd like to create a custom element (that basically looks like a circle) that the user can toggle its visibility through the Visibility/Graphics Overrides settings panel. Is this actually possible? 

 

Much appreciate any help here 🙂 

Message 5 of 6

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi @aryan4WGLU,

 

A Element with a subcategory in the Site Category would always be a Model element (3D).

 

So you would need to create a Model Family or a Directshape object with a Solid and set it's GraphicsStyleId to one with the correct subcategory.

 

- Michel

 

 

 

0 Likes
Message 6 of 6

aryan4WGLU
Participant
Participant
Accepted solution

Thank you Michel @TripleM-Dev.net

 

This solved my problem! 

 

For future reference. I created my custom category under Site like so:

 

Categories categories = doc.Settings.Categories;
Category siteCategory = categories.get_Item(BuiltInCategory.OST_Site);
Category customSubCat = categories.NewSubcategory(siteCategory, "CUSTOM COORDINATES");
doc.Regenerate();

 

 

 

And then created a DirecteShape using the following snippet (adopted from the Docs) 

 

List<Curve> profile = new List<Curve>();

// first create sphere with 2' radius
XYZ center = XYZ.Zero;
double radius = 2.0;
XYZ profile00 = center;
XYZ profilePlus = center + new XYZ(0, radius, 0);
XYZ profileMinus = center - new XYZ(0, radius, 0);

profile.Add(Line.CreateBound(profilePlus, profileMinus));
profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));

CurveLoop curveLoop = CurveLoop.Create(profile);
SolidOptions options = new SolidOptions(ElementId.InvalidElementId, customSubCat.GetGraphicsStyle(GraphicsStyleType.Projection).Id);

Autodesk.Revit.DB.Frame frame = new Autodesk.Revit.DB.Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);


if (Autodesk.Revit.DB.Frame.CanDefineRevitGeometry(frame) == true)
{
    Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);

    // create direct shape and assign the sphere shape
    DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Site));

    ds.ApplicationId = "Application id";
    ds.ApplicationDataId = "Geometry object id";
    ds.SetShape(new GeometryObject[] { sphere });
}

 

 

Thanks again!

0 Likes