Quantcast
Channel: All Revit API Forum posts
Viewing all 67020 articles
Browse latest View live

How to modify the rebar bar segments dimensions?

$
0
0

Hi,

 

What is the equivalent in Revit API (code) of editing a Rebar Bar dimensions within the properties palette?

 

revit_rebar_bar_dimensions.png

 

I tried to get parameters (get_parameters) on Rebar element and I noticed that there is shared parameters named "Length 1", "Length 2", ... (according to the number of bar's segments).

 

Any suggestions are welcomed.

Best regards,

Jonathan


Setting New Compound Structure for WallType Does not Update LayerID of CSL

$
0
0

CSL:CompoundStructureLayers

1)I have a WallType and need to Change the compound structure of WallType.

private void updateCompoundStructure(WallType wT)
{
  IList<Autodesk.Revit.DB.CompoundStructureLayer> csl = new     List<Autodesk.Revit.DB.CompoundStructureLayer>();

   csl.Add(new Autodesk.Revit.DB.CompoundStructureLayer()
                                {
                                    DeckEmbeddingType = deck,
                                    DeckProfileId = profileId,
                                    Function = structureFunction,
                                    LayerCapFlag = item.LayerCapFlag,
                                    MaterialId = materialId,
                                    Width = item.Thickness
                                });

CompoundStructure cs = CompoundStructure.CreateSimpleCompoundStructure(csl);
if (cs.IsValid(dbDoc, out IDictionary<int, CompoundStructureError> errMap, out IDictionary<int, int> twoLayerErrorMap))
{
 wallType.SetCompoundStructure(cs);
} }

The walltype compound structure is updated properly

 

But,CompoundStructureLayer.LayerId is the read-only field we cannot update it
for all the CompoundStructureLayer's LayerId I get is like 0

 

2) when i read the compoundStructure form WallType it  gives LayerID as at 0 th index as 0,

  at 1 st  index as 1

 at 2nd inndex as 2... and so on

is there any way to Update The layerID of compound Structure?

 

 

 

Re: Made a new 3DView. It's empty. Why?

$
0
0

first of all, you might make a list of the error elements. We can then see the Revit classes to which the elements belong.

			List<ElementId> errorIds ;
			StringBuilder sb = new StringBuilder();
			foreach( ElementId id in errorIds)
			{
				Element e = doc.GetElement(id);
				sb.AppendLine(string.Format("<{0}> {1}  [{2}]",id, e.Name, e.GetType()));
			}
			TaskDialog.Show("debug", sb.ToString());

 

I think you should make your own ViewFamilyType, without ViewTemplate so all elements are Visible on creation.

You can then hide all elements (that can be hidden) except the error elements.

			List<ElementId> errorIds ;
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>()
                                                 where v.ViewFamily == ViewFamily.ThreeDimensional
                                                 select v).First();
            View3D view;
            using (TransactionGroup tg = new TransactionGroup(doc, "create Error View"))
            {
            	tg.Start();
		        using (Transaction t = new Transaction(doc, "Create Issues View"))
        	    {
            	    t.Start();
            	    // create new ViewFamilyType without ViewTemplate
            	    ViewFamilyType my_type = viewFamilyType.Duplicate("Error_View") as ViewFamilyType;
					my_type.get_Parameter(BuiltInParameter.DEFAULT_VIEW_TEMPLATE).Set(ElementId.InvalidElementId);
					view = View3D.CreateIsometric(doc, my_type.Id);

					// Hide DWG , Analytical Categories, Annotaion
            	    view.AreImportCategoriesHidden = true;
            	    view.AreAnalyticalModelCategoriesHidden = true;
            	    view.AreCoordinationModelHandlesHidden = true;
            	    view.AreAnnotationCategoriesHidden = true;
            	    // Hide RVT Links
            	    view.SetCategoryHidden(new ElementId(BuiltInCategory.OST_RvtLinks),true);
            	    // show Parts
            	    view.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY).Set(2);
            	    t.Commit();
            	}
		        IEnumerable<Element> elemsInView = new FilteredElementCollector(doc,view.Id)
		        	.WhereElementIsNotElementType()
		        	.Excluding(errorIds);
		        List<ElementId> elemsToHide = new List<ElementId>();
		        foreach(Element e in elemsInView)
		        {
		        	if (e.CanBeHidden(view) ) elemsToHide.Add(e.Id);
		        }
		        using  (Transaction t = new Transaction(doc, "hide elements"))
		        {
		        	t.Start();
		        	view.HideElements(elemsToHide.ToList());
		        	t.Commit();
		        }
		        tg.Assimilate();
            }
            this.ActiveUIDocument.ActiveView = view;
            this.ActiveUIDocument.ShowElements(errorIds);

Last thing to check (if needed) Visibility of Worksets, turn on all worksets. [ view.SetWorksetVisibility() ]

Re: Sdk example combobox in datagrid.

$
0
0

Hi Jeremy,

 

I already find the solution to get the ComboBox filled. So that problem is solved.

 

With this form i like to create new sheets and update extisting sheets. But the combobox don't recognize the existing TitleBlock in combination with the existing Sheet. How can i make the connection between both? so it gets existing one displayed as selected index in the combobox. in my case it should be a A0 metric.

 

It's the last step i need to know...

 

The result i'm getting now is like this and also my part of the code:

SheetList.jpg

 

 

namespace Levelapp
{
    [Transaction(TransactionMode.Manual)]
    public class FilterLevel : IExternalCommand
    {

        public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            using (Transaction t = new Transaction(doc, "level"))

                try
                {
                    t.Start("filter");
                    getView = new SortableBindingList<LevelResource>();
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    List<ViewSheet> views = collector.OfClass(typeof(ViewSheet))
                    .OfType<ViewSheet>().OrderBy(lev => lev.SheetNumber).ToList();
                    {
                        foreach (ViewSheet v in views)
                        {
                            LevelResource dataInRow = new LevelResource();

                            dataInRow.Name = v.Name;
                            dataInRow.Number = v.SheetNumber;

                            //dataInRow.Id = v.Id.IntegerValue;

                            getView.Add(dataInRow);
                        }
                            getSheets = new List<LevelResource>();
                            FilteredElementCollector titleBlockSymbols = new FilteredElementCollector(doc)
                            .OfClass(typeof(FamilySymbol))
                            .OfCategory(BuiltInCategory.OST_TitleBlocks);

                         foreach (FamilySymbol fs in titleBlockSymbols)
                         {
                            LevelResource titleDrop = new LevelResource();
                            titleDrop.Title = fs.Name;                      
                            //titleDrop.Id = fs.Id.IntegerValue;

                            getSheets.Add(titleDrop);
                                
                         }
                                                
                         using (LevelView displayForm = new LevelView(this))
                         {
                            displayForm.ShowDialog();
                         }

                            t.Commit();
                            return Result.Succeeded;
                        }
                    }                


                catch (Exception ex)
                {
                    // If something went wrong return Result.Failed
                    message = ex.Message;
                    return Result.Failed;
                }

        }

    
        public SortableBindingList<LevelResource> getView;
        /// <summary>
        /// Store all levels' datum in system
        /// </summary>
        public SortableBindingList<LevelResource> FoundViews
        {
            get
            {
                return getView;
            }
            set
            {
                getView = value;
            }
        }

        public List<LevelResource> getSheets;

        public List<LevelResource> FoundSheets
        {
            get
            {
                return getSheets;
            }
            set
            {
                getSheets = value;
            }
        }
    }
}

Binding the data:

        public LevelView(FilterLevel opt)
        {
            InitializeComponent();

            m_filterLevel = opt;

            TitleBlockName = new DataGridViewComboBoxColumn();
            TitleBlockName.HeaderText = "Title Block";
            TitleBlockName.Width = 200;
            TitleBlockName.DataSource = new ArrayList(m_filterLevel.FoundSheets);
            TitleBlockName.ValueMember = "Title";
      
            SheetName = new DataGridViewTextBoxColumn();
            SheetName.HeaderText = "Name";
            SheetName.Width = 200;
            SheetNumber = new DataGridViewTextBoxColumn();
            SheetNumber.HeaderText = "Number";
            SheetNumber.Width = 200;

            dataGridView1.Columns.AddRange(new DataGridViewColumn[] { TitleBlockName, SheetName, SheetNumber });
            
            bindingSource1.DataSource = typeof(LevelResource);
            dataGridView1.AutoGenerateColumns = false;            
            dataGridView1.DataSource = bindingSource1;
            TitleBlockName.DataPropertyName = "Title";
            SheetName.DataPropertyName = "Name";
            SheetNumber.DataPropertyName = "Number";

            bindingSource1.DataSource = m_filterLevel.FoundViews;

Re: Loading macro failed error.

$
0
0

Hopefully that worked since you marked it as solved.

 

If not, you could always start a new Module, and start a new Macro in that Module.  Then build it before adding any other code.  It should build without any problems.

 

Then add your code.  If it won't build after that, its something wrong with your code.

 

Re: Single Wall finish

Re: How to modify the rebar bar segments dimensions?

$
0
0

Hi,

 

I maybe have the equivalent code of editing a Rebar Bar dimensions within the properties pallette.

 

Instead of 'Length 1', 'Length 2', etc...my bar's segments are letters like ' B ', ' C ', ' D ' etc.

 

My project units settings are 'mm' instead of 'cm'.

 

So there are some differences.

 

Hope this will give you an idea how to approach this.

Cheers,

So-Chong

         public void setParametersBarSegmentsValue()
        {
            UIDocument uidoc = this.ActiveUIDocument;
            Document doc = uidoc.Document;
            
            Reference myRef = uidoc.Selection.PickObject(ObjectType.Element);
            
            Element elem = doc.GetElement(myRef);
        
            bool result = false;
            double setB = Constant.MmToFeet(900);
            double setC = Constant.MmToFeet(4000);
            double setD = Constant.MmToFeet(900);
            
            using (Transaction t = new Transaction(doc, "modify rebar segment"))
            {                
            t.Start();
              
            foreach (Parameter p in elem.Parameters)
            {
                if(p.Definition.Name.Equals("B"))
                {
                    result = p.Set(setB);
                }
                
                if(p.Definition.Name.Equals("C"))
                {
                    result = p.Set(setC);
                }
                
                if(p.Definition.Name.Equals("D"))
                {
                    result = p.Set(setD);
                }
            }
            
            t.Commit();              
            }
        }
        
          public class Constant
          {
            /// <summary>
            /// Conversion factor to convert millimetres to feet.
            /// </summary>
            const double _mmToFeet = 0.0032808399;
        
            public static double MmToFeet(double mmValue)
            {
              return mmValue * _mmToFeet;
            }
          }

Rebar segments.png

Re: Listing all views in a project on a Winform throwing an exception

$
0
0

 

nvm. I may have solved the issue.


Scheduling multiple types not showing separately

$
0
0

I am currently having an issue when I attempt to schedule using shared parameters. I have a furniture family with about 3 types that are spread throughout the model. When I schedule the furniture family, it hides the family name and only maintains the constant height shared parameter in the schedule, while showing the count of 3 at the end. 

 

How can I schedule these multiple instances of the family as separate lines in the schedule. 

 

Hope that makes sense. Thanks in advance!

Re: Can not distinguish the rebar shape when I use the api CreateFromCurves?

$
0
0

How are you calling the CreateFromCurves utility?  there are a couple of options at the end of the params list which control some auto-finding behavior.  Have you tried setting useExistingShapeIfPossible to false?

I'm riffing here but a quick look at the points you are supplying, the rebar is not ikely to match any of the existing shape definitions so Revit will need to create a new one for you.  I would expect that it could do that unless the createNewShape parameter is set to false. 

 

useExistingShapeIfPossible Type: System Boolean
Attempts to assign a RebarShape from those existing in the document. If no shape matches, NewRebar returns or creates a new shape, according to the parameter createNewShape. When both parameters are "true", the behavior is the same as sketching rebar in the UI. At least one of these parameters must be "true". If the RebarShapeDefinesHooks flag in ReinforcementSettings has been set to false, and a RebarShape cannot be found with both matching curves and hooks, then this method will perform a second search, ignoring hook information.

Re: Hide ribbon tab if family document active

$
0
0

You could also consider implementing an IExternalCommandAvailability class.  This class can be assigned to a button an will allow you to "compute" whether the button should be enabled or not.  You could check for family document there and disable the buttons (instead of hiding the tab which can lead to user confusion).

 

In your pushbutton data object you can set the availability class like this:

myCommandBtnData.AvailabilityClassName = "myNameSpace.myCommandAvailability";

 

the class looks like this:

 

    class myCommandAvailability : IExternalCommandAvailability
    {
        public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
        {
                if (applicationData.ActiveUIDocument.Document.IsFamilyDocument)
                      return false;
        }

If you want to get fancy, you can keep a reference to the button and change the text or tooltip to help the user understand why they command is disabled in a particular situation.

 

 

How to read near clip offset of an elevation view?

$
0
0

I need to read near clip offset of the active elevation view. I notice that there are two properties: VIEWER_BOUND_ACTIVE_NEAR and VIEWER_BOUND_OFFSET_NEAR. Ideally these should provide whether the near clip offset is active and its offset respectively. But I always find their values to be 0, even if I move the near clip offset around. Here's the code to read the near clip offset:

 

int active = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_NEAR).AsInteger();
double offset = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_NEAR).AsDouble();

Am I doing anything wrong here or is this a bug?

Re: How to read near clip offset of an elevation view?

$
0
0

It seems that the view origin is on the near clip plane. I should be able to get the near clip plane based on view direction and origin.

Re: How to modify the rebar bar segments dimensions?

$
0
0

Yes, I believe Chong is right, if you check the value with Lookup tool, you will see the relationship of API as follow:

  

Screen Shot 2018-09-26 at 9.42.24 AM.png

 

Re: Can not distinguish the rebar shape when I use the api CreateFromCurves?

$
0
0

Dear kmarsh:

I use the params in the end , true and true.Which should mean,try to find a rebar shape exist ,if not find, will create a rebar shape.

If I change it as you say,the useExistingShapeIfPossible false, it also show the attention, can not distinguish the rebar shape (I had tried as you say).

I get no method to solve the problem untill now.

 


Re: circuits grouping

$
0
0

I am not sure about panel schedule, but if I understand correctly, if you group some elements, these elements will be in the same group, you can check the group id to see if they are same by method:

public ElementId GroupId { get; }

 

 

Or get all the members in the group by method:

public IList<ElementId> GetMemberIds()

 

If anything I misunderstand, please send me a Revit file with the group of circuits in panel schedule and I will investigate more.

Re: Made a new 3DView. It's empty. Why?

$
0
0

Thank you for your detailed answer.  I like your approach.  I'll see if I can port it over to my code, and make this work.  I have a few questions.

 

What does this line mean:

 

 

// create new ViewFamilyType without ViewTemplate
            	    ViewFamilyType my_type = viewFamilyType.Duplicate("Error_View") as ViewFamilyType;
					my_type.get_Parameter(BuiltInParameter.DEFAULT_VIEW_TEMPLATE).Set(ElementId.InvalidElementId);

 

I looks like we are duplicating the "first" view found via the filter criteria further up the code, so the file is basically taking an existing view and duplicating it.  Is that better than the "Create" method?

 

Then you are getting a parameter  and setting it to an ElementId enumeration of invalid element?  Why?  Is ElementId.InvalidElementId not an enumeration?  

 

 

view.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY).Set(2);

What is this line doing exactly?  Why "2?"

 

 

 

I like this line:

 

		        IEnumerable<Element> elemsInView = new FilteredElementCollector(doc,view.Id)
		        	.WhereElementIsNotElementType()
		        	.Excluding(errorIds);

I see what you do later with checking the elements to make sure they are eligible for "hiding."  Too bad the filter can't have a ".CanBeHidden()" suffix to eliminate that.  But I'm sure it doesn't require a lot resources.

 

 

 

 

All of this is really good.  I'll try it out.  Aside from the "view.get_Parameter(BuiltInParameter...." coding, I have seen most of what you are providing, but never employed it in that way.  Much smarter looping and filtering in your suggestion than my original code, but I'm still negotiating how Revit works.

 

 

 

 

 

 

 

 

Spot elevation problem

$
0
0

WHEN I PLACE A SPOT ELEVATION, MY ADDED PARAMETER IS NOT VISIBLE WHEN I SPOT THE LEVEL AND MOVE IT DOWNWARDS. REFER TO ATTACHED IMAGE. I ALSO WANT TO KNOW HOW TO REDUCE MY LEADER SIZE.SPOT.png

Re: How to modify the rebar bar segments dimensions?

$
0
0

Thank you for your replies, I was able to set dimensions values with your code snippet, but I guess this is too dangerous to use string comparaison. These parameters have different names across Revit versions and languages. My customers uses 4 different languages...

 

I did other research and noticed that you can get the RebarShapeDefinitionBySegments from the RebarShape of the rebar element. Then it's possible to loop on each RebarShapeSegment and theirs constraints. Finally, it should have a RebarShapeConstraintSegmentLength and there is a GetParamId method to find (I guess) the shared parameter element ID.

 

I hoped there is a method equivalent to GetShapeDrivenAccessor to manage the dimensions of the bar. Sometimes, it takes several to understand which parameter and how to modify it in Revit, not really developers friendly.

 

Best regards,

Jonathan

element modification exception.

$
0
0

Druing studying of Revit API  Element Modification, i got this exception message. how could i figure this one??

error.png

Viewing all 67020 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>