newAlignment on familyInstance center reference and a DetailCurve

newAlignment on familyInstance center reference and a DetailCurve

Anonymous
Not applicable
1,150 Views
2 Replies
Message 1 of 3

newAlignment on familyInstance center reference and a DetailCurve

Anonymous
Not applicable

I have been trying to get my head around how to get a familyInstance's referencePlane (Center Left/Right) Reference, to align and lock to a line on a view.

 

So far I have been able to align simple DetailCurve's to each other with the newAlignment() command, but I am having issues getting the Center (Left/Right) referencePlane's reference from inside a faimlyInstance using get_geometry().

 

I have been able to find the lines within the get_geometry but when I use the newAlignment() command it states there was an issue with the command, although the family and the line are on the same axis and ready for alignment locking.

 

Below is the code I have used:

 

 

double ftMM = 1 / 304.8; // Feet to Millimetres
Options opt = new Options();
opt.ComputeReferences = true;
opt.IncludeNonVisibleObjects = true;
opt.View = doc.ActiveView;

DetailCurve circuitLine = doc.Create.NewDetailCurve(draftView, Line.CreateBound(new XYZ(0, 0, 0) * ftMM, new XYZ(0, 50, 0) * ftMM)); // Basic Circuit Line
DetailCurve circuitLine2 = doc.Create.NewDetailCurve(draftView, Line.CreateBound(new XYZ(0, 70, 0) * ftMM, new XYZ(0, 150, 0) * ftMM)); // Basic Circuit Line

doc.Create.NewAlignment(draftView, circuitLine.GeometryCurve.Reference, circuitLine2.GeometryCurve.Reference); // This works fine.

FamilyInstance deviceInstance = doc.Create.NewFamilyInstance(new XYZ(0, 9, 0) * ftMM, deviceFamily, draftView); // Device Type

What would be the best method to get the standard referencePlane = Center (Left/Right) from the familyInstance inserted in the code above?

 

I have used the following to get all the lines within the familyInstance:

 

GeometryInstance geoElement = deviceInstance.get_Geometry(opt).First() as GeometryInstance;

foreach (var item in geoElement.GetInstanceGeometry())
  {
    Line lineObj = item as Line;
    if (lineObj != null)
      {
        TaskDialog.Show("Test Line", lineObj.Reference.ToString());
      }
   }

I have tried using any of the lines within the above code and none seemed to work with the newAlignment() command.

 

0 Likes
Accepted solutions (1)
1,151 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

I ammended my code to find only the InstanceGeometry that is on the same X.Axis as the DetailCurve with the following code:

 

GeometryInstance geoElement = deviceInstance.get_Geometry(opt).First() as GeometryInstance;
foreach (var item in geoElement.GetInstanceGeometry())
  {
    Line lineObj = item as Line;
    if (lineObj != null)
      {
        if (circuitLine.GeometryCurve.GetEndPoint(0).X == lineObj.GetEndPoint(0).X)
          {
            TaskDialog.Show("Test", circuitLine.GeometryCurve.GetEndPoint(0).ToString() + " ||| " +
circuitLine.GeometryCurve.GetEndPoint(1).ToString() + " ||| " +
lineObj.GetEndPoint(0).ToString() + " ||| " +
lineObj.GetEndPoint(1).ToString());
           deviceReference = lineObj.Reference;
         }
       }
     }

This shows a dialog that both objects are on the same axis and yet still the newAlignment() command fails, would anyone know what I am missing?

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

After reading a lot more on the topic I found that is was the GetInstanceGeometry() was the issue.

 

GetInstanceGeometry only returns a copy of the geometry references and cannot be used for things like dimension or newAlignment commands.

 

The solution was to use the GetSymbolGeometry() instead, this would return coordinated based on the family instance instead of the document coordinate system, but can be used as a reference in the newAlignment command.

 

 

        public Reference centerXRef(FamilyInstance fi)
        {
            Reference Reference = null;
            Options opt = new Options();
            opt.ComputeReferences = true;
            opt.IncludeNonVisibleObjects = true;
            opt.View = doc.ActiveView;
            GeometryInstance geoElement = fi.get_Geometry(opt).First() as GeometryInstance;
            foreach (var obj in geoElement.GetSymbolGeometry())
            {
                Line lineObj = obj as Line;
                if (lineObj != null)
                {
                    if (lineObj.GetEndPoint(0).X == 0 && lineObj.GetEndPoint(1).X == 0) Reference = lineObj.Reference;
                } 
            }
            return Reference;
        }

 

0 Likes