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

Re: CADLinks

$
0
0

Hi!

 

First of all, you should get CADLinkType, it represents both CAD links and CAD imports, dwgs, dxfs and others.

It has Reload method, but be careful, CAD imports are not ExternalFileReferences; they are brought completely into the document and maintain no connection to their original file. Check IsLink to distinguish between links and imports.

 

Reload method arrived in the API since Revit 2018, there is no appropriate method in older Revit versions


Temporary Transaction Trick Exception

$
0
0

Hi,

I'm trying to use a trick of transactions. I remove everything from the wall and check the intersection of the edge of the wall and the line from the side of the room. But I have an error when working with

ICollection <ElementId> generatingElementIds =    wall.GetGeneratingElementIds (edges [0]);

An unhandled exception of type 'System.AccessViolationException' occurred in RevitDBAPI.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

What am I doing wrong?

 

  SetComparisonResult intersectionPoint = SetComparisonResult.Disjoint;
 using (Transaction ff=new Transaction(doc,"Get intersections"))
      {
             ff.Start();
 using (SubTransaction deleteTransaction = new SubTransaction(doc))
        {
            deleteTransaction.Start();

              if (idsFamilyInstance.Count > 0)
                  {
                    ICollection<Autodesk.Revit.DB.ElementId> deletedIdSet = new List<ElementId>();
                    deletedIdSet = doc.Delete(idsFamilyInstance);

                    if (0 == deletedIdSet.Count)
                     {
                        throw new Exception("Deleting the selected elements in Revit failed.");
                     }
                 }
                   doc.Regenerate();

  Options optionswall = new Options();
  optionswall.ComputeReferences = true;
  GeometryElement geometryElement = wall.get_Geometry(optionswall);

     foreach (GeometryObject geometry in geometryElement)
          {

            Solid geomSolidwall = geometry as Solid;

            // Get the faces
            foreach (Face face in geomSolidwall.Faces)
               {
                  //  doc.Regenerate();
                  intersectionPoint = face.Intersect(line);
                  if (intersectionPoint != SetComparisonResult.Disjoint)
                     {
                        break;
                     }
                 }

                 }

                    deleteTransaction.RollBack();
                    doc.Regenerate();

             }
                ff.Commit();
             }

               if (intersectionPoint != SetComparisonResult.Disjoint)
                    {

                        ICollection<ElementId> generatingElementIds =
                        wall.GetGeneratingElementIds(edges[0]);
              foreach (ElementId generatingElementId in generatingElementIds)
                     {
                       Element wallfromgenerating = doc.GetElement(generatingElementId);
                              if (wallfromgenerating is FamilyInstance)
                                 {

                                  }
                }

 

Re: Correlation between FamilyInstance LocationPoint & Transformation Origin

$
0
0

Hi Jeremy,

Thanks for the reply.  I will put together an MRC, but until then here are the answers to your other questions.

 

Context

Revit 2016 R2 Update 7

I am drawing Lines around the perimeter of family instances.  This is done by drawing the lines in the project space, then creating copies transformed into the family instance's space.

 

Pseudo Code:

var trans = familyInstance.GetTotalTransform();
var lines = GetPerimeter(familyInstance).Select(l => l.CreateTransformed(trans);

For most family instances this works , but I found some where the translation portion of the transform was off, by several feet, and have yet to determine what could cause that; like a basic misunderstanding on my part, or something in the way the family is constructed.  Hence my posted question.

 

The Workaround

The workaround is to construct my own transform instead of relying on the transform returned by the GetTotalTransform() method.

 

 

        public static Transform GetTransformation(this FamilyInstance familyInstance)
        {
            var insertPoint = familyInstance.GetLocationPoint();

if (insertPoint == null) {
throw new ArgumentException($"Expected a point based family instance, <{familyInstance.Id}>");
}
var xAxis = familyInstance.HandOrientation.Normalize(); var yAxis = familyInstance.FacingOrientation.Normalize(); var zAxis = xAxis.CrossProduct(yAxis).Normalize(); var transForm = Transform.Identity; transForm.Origin = insertPoint; transForm.BasisX = xAxis; transForm.BasisY = yAxis; transForm.BasisZ = familyInstance.IsFlippedOnSingleAxis() ? zAxis.Negate() : zAxis; return transForm; } private static bool IsFlippedOnSingleAxis(this FamilyInstance familyInstance) { var singleAxisIsFlipped = familyInstance.FacingFlipped ^ familyInstance.HandFlipped; return singleAxisIsFlipped; }

This works fine for my purposes, but I still want to know the piece of the puzzle I'm missing.  Hopefully the MRC will help.

 

 

Edit Tick Mark - Dimension Type

$
0
0

Hi guys,

I'd like to edit a dimension style: I duplicated a dimensionType and now I would edit the "Tick Mark" setting it to "None". I have used Revit LookUp: it's the BuiltInParameter.DIM_LEADER_ARROWHEAD, its Storage Type is ElementId and "None" stands for a <null> Id.

Now, how can I set its value? I can't find out how retrieve "none" and its corrispondent Id.

 

Thanks in advance

Re: Edit Tick Mark - Dimension Type

$
0
0

Hi!

Use

parameter.Set(ElementId.InvalidElementId)

Re: Temporary Transaction Trick Exception

$
0
0

I cannot read your code due to the random indentation.

 

That makes it hard for me to tell how the transactions are nested.

 

All I can say off-hand is that the call to the constructor here (using `new`) is totally superfluous, because the list is re-created anyway by the Delete method: 

 

  ICollection<ElementId> deletedIdSet = new List<ElementId>();
  deletedIdSet = doc.Delete(idsFamilyInstance);

 

Cheers,

 

Jeremy

 

Re: BoundingBox rotation not 100% correct unless it's set 3 times

$
0
0

Maybe your rotation is totally different from what you expect.

 

Try it out with a model line so you can see exactly what happens.

 

Are you using radians or degrees to set it up?

 

That might cause confusion.

 

30.0 sounds like degrees to me. 

 

Mathematics , geometry and the Revit API generally always use radians.

 

Cheers,

 

Jeremy

 

Re: CADLinks

$
0
0

Thank you for your prompt response and apologies for my error.

You are correct that I should be using CADLinkType. 

This is what I should have posted within my original question:

 

IList<Element> CADlist = (IList<Element>)new FilteredElementCollector(openDoc).OfClass(typeof(CADLinkType)).WhereElementIsElementType().ToList<Element>();

 

I looking to utilise Reload as you suggest but I am now struggling with how to set the new location for the link.

 

An example would be much appreciated.


Re: CADLinks

$
0
0

Am I correct in my understanding that using Reload link has to be undertaken as part of TransmissionData?

If this is the case my understanding is that any links created (Reloaded) will only be implemented next time the document is opened, thus resulting in the document being updated next time it is opened?

 

My preferred option would be to update the link to avoid this update, which I have achieved for DWG only using

 

trans.Start();
cadLinkType.LoadFrom(string Path);
trans.Commit();

 Is it possible to achieve the same for the remaining CADLinkTypes?

Re: BoundingBox rotation not 100% correct unless it's set 3 times

$
0
0

Thanks for your reply Jeremy, 

 

Well what confused me was that even if the transformation is wrong, it should be wrong every time right ? it seems really odd to me that setting the box to the exact same object 3 times yields different results. I'm calculating the transformation like this:

double alpha = Math.Atan2(end.Y - start.Y, end.X - start.X); 
//some adjustments to alpha based on the elevation direction; Transform rotation = Transform.CreateRotationAtPoint(XYZ.BasisY, alpha, midpoint);

The angle should be in radians, I said 30.0 degrees just as an example but I'm not passing plain degrees to revit.

I attached two images, one is how the object is rotated if I set the rotation once, and the other one if i set the rotation (to the exact same transformed BoundingBox) 3 times.

 

By the way, is not for all cases that repeated rotations are different. For some angles, it's rotated completely the first time, for some others it takes 2 rotations, and for some others 3. 

 

I'll use the transformation on model lines as you suggest to see if it behaves as expected as you suggest.

set rotation 3 timesset rotation 3 timesset rotation 1 timeset rotation 1 time

Thanks again!

Re: Temporary Transaction Trick Exception

$
0
0

I apologize for the indentation, I was in a hurry. Now I have slightly corrected the code. After I applied the temporary transaction trick, I get an exception at the time of the ICollection <ElementId> generatingElementIds =
                                             wall.GetGeneratingElementIds (edges [0]);
Before the application of transactions, this exception did not appear. Perhaps the wall needs to be found inside the transaction?

           SetComparisonResult intersectionPoint = SetComparisonResult.Disjoint;

                                using (Transaction ff=new Transaction(doc,"sssss"))
                                {
                                    ff.Start();
                                 
                                using (SubTransaction deleteTransaction = new SubTransaction(doc))
                                {
                                    deleteTransaction.Start();

                                    if (idsFamilyInstance.Count > 0)
                                    {
                                        ICollection<Autodesk.Revit.DB.ElementId> deletedIdSet = doc.Delete(idsFamilyInstance);

                                        if (0 == deletedIdSet.Count)
                                        {
                                            throw new Exception("Deleting the selected elements in Revit failed.");
                                        }
                                    }
                                    doc.Regenerate();
                                    Options optionswall = new Options();
                                    optionswall.ComputeReferences = true;
                                    GeometryElement geometryElement = wall.get_Geometry(optionswall);
                                    foreach (GeometryObject geometry in geometryElement)
                                    {
                                        Solid geomSolidwall = geometry as Solid;
                                        // Get the faces
                                        foreach (Face face in geomSolidwall.Faces)
                                        {
                                            intersectionPoint = face.Intersect(line);
                                            if (intersectionPoint != SetComparisonResult.Disjoint)
                                            {
                                                break;
                                            }
                                        }

                                    }

                                    deleteTransaction.RollBack();

                                }//end subtransaction
                                    ff.Commit();
                                }//end transaction
                                if (intersectionPoint != SetComparisonResult.Disjoint)
                                    {
//on this line I get an exception
                                        ICollection<ElementId> generatingElementIds =
                                            wall.GetGeneratingElementIds(edges[0]);

                                    }

Re: Visibility of DWG layer

$
0
0

Hi Jeremy,

 

Finally had time to put this into a simple project.  Project has a basic macro that will draw a detailed region around the visible layer in the linked cad. 

 

Thanks again.

Ryan

Re: room walls direction

$
0
0

Hi,

Thanks for the reply.

Assume I am in the room and I  am looking at the wall. I need to get this direction.

Thanks & Regards

Sanjay Pandey

How to get a room parameter, which was defined by a third party

$
0
0

I am work on a shared project with many other people. One defined a custom parameter, which we must fill. I now want to fill that custom parameter with values from my database. But I can figure out, how to access this custom parameter which was created by a third party, since I don`t have a GUID...

 

Any help is much appreciated

 

p.s. Attached is a screenshot of the parameter I want to change

Re: CADLinks

$
0
0

You can perform operation with transmission data, using specific facilities or just work in current document, loading and reloading links is immediate operation in the last case.

 

This is a sample, that reloads linked cadlinks:

var uiapp = commandData.Application;
var uidoc = uiapp.ActiveUIDocument;
var doc = uidoc.Document;

var collector = new FilteredElementCollector(doc);

var cadLinkTypes = collector
	.OfClass(typeof (CADLinkType))
	.OfType<CADLinkType>()
	.Where(x => x.IsExternalFileReference())
	.ToList();

using (var transaction = new Transaction(doc, "reload all"))
{
	transaction.Start();

	foreach (var cadLinkType in cadLinkTypes)
		cadLinkType.Reload();

	transaction.Commit();
}

return Result.Succeeded;

Re: How to get a room parameter, which was defined by a third party

$
0
0

query the room's parameters' definitions' by name, e.g.:

 

var parameter = room.Parameters.Cast<Parameter>().Where(p => p.Definition.Name == "Abteilung").FirstOrDefault();

if (parameter != null) parameter.SetValueString("Schaflabor");

Re: How to get a room parameter, which was defined by a third party

$
0
0

Oh, no, don't do this in such way, please.

 

There is an Element.LookupParameter method, that is available since Revit 2015

 

You can do it simply:

var parameter = room.LookupParameter("Abteilung");

if (parameter != null) parameter.SetValueString("Schaflabor");

But you should be careful, element can have more than one parameter with such name. May be, the best way is to retrieve parameters via their guid, you can explore everything in Revit model via RevitLookup tool, install and use it, it you don't at this moment

Lock/grey-out/freeze the element parameters, in a winform datagrid.

$
0
0

The winform has a datagrid linked to the properties tab of revit model.
Upon selection of an element, the parameters are obtained to this datagrid.

I want to disable editing for read only parameter values in the form,

and update the revit model once the parameters that are modifiable are edited by the user.

Re: Correlation between FamilyInstance LocationPoint & Transformation Origin

Re: CADLinks

$
0
0

Again thank you for your response and the code sample.

 

It is a much neater and compact solution than I was currently working on, however in some cases the location or name of the linked files has changed and this does not allow for these changes.

 

I assume there must be a way to update the file name or location and utilise this within the reload.

The API chm suggests to me that this should be possible by utilising the IExternalResourceServer  and again I am clearly missing the obvious as I have not been able to achieve this.

Your help and any code guidance would be much appreciated.

 

 

Viewing all 66860 articles
Browse latest View live


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