SpatialElementGeometryCalculator (DirectShape Python , GetInstanceCutoutFromWall and OpeningCut Problem)

SpatialElementGeometryCalculator (DirectShape Python , GetInstanceCutoutFromWall and OpeningCut Problem)

yjeugene888
Explorer Explorer
705 Views
1 Reply
Message 1 of 2

SpatialElementGeometryCalculator (DirectShape Python , GetInstanceCutoutFromWall and OpeningCut Problem)

yjeugene888
Explorer
Explorer

I am trying to port over @Anonymous 's SpatialElementGeometryCalculator code into python and encounter several problem that I am not sure how to fix.

https://github.com/jeremytammik/SpatialElementGeometryCalculator 

 

As I trying to understand how does code works, I have faced various problem with IronPython2. 

1. I am unable to port over DirectShape code as it has the error "expect Int, got Solid". I am unable to figure out why the DirectShape.SetShape() has problem. I ensure that the SetShape has receive correct argument List[GeometryObject](Solid) but still unable to fix it. I thought it was an overload issue and added more arguments, but it didn't fix it.

https://www.revitapidocs.com/2022/d8642243-fb35-0cbe-08d8-df4518929946.htm 

https://forums.autodesk.com/t5/revit-api-forum/create-direcshape/td-p/8855402 

https://forum.dynamobim.com/t/directshape-setshape/70368/2 

 

 

 

def CreateDirectShape( doc, transientSolid, dsName ):
    catId = ElementId(BuiltInCategory.OST_GenericModel)

    addInId = doc.Application.ActiveAddInId
    # DirectShape ds = DirectShape.CreateElement(doc, catId, addInId.GetGUID().ToString(), "" ); // 2016

    ds = DirectShape.CreateElement(doc, catId)  # 2020
    ds.ApplicationId = addInId.GetGUID().ToString()  # 2020
    ds.ApplicationDataId = ""  # 2020

    if ds.IsValidGeometry(transientSolid):
        print('here2')
        ds.SetShape(List[GeometryObject](transientSolid), DirectShapeTargetViewType.Default)
        print('here')
    else:
        result = ShapeCreator.GetTessellatedSolid(doc, transientSolid)
        ds.SetShape(result.GetGeometricalObjects())

    ds.Name = dsName
    return ds

 

 

 

2. GetInstanceCutoutFromWall Exception

I have issue with GetInstanceCutoutFromWall where sliding door don't have OpeningCut object and it failed. I don't know what to do. From what i have search in the forum, 

https://forums.autodesk.com/t5/revit-api-forum/getinstancecutoutfromwall-exception/m-p/8232031

(does it help with calculate area or generate opening cut?)

https://forums.autodesk.com/t5/revit-api-forum/area-of-a-wall-opening/m-p/7867388#M29629 

(deleting element seems risky)

Even from the old SpatialElementGeometryCalculator code, there is a old method using parameter Height and Width to calculate area. But that does not guarantee correct area. 
Is there better way to calculate door or window area where GetInstanceCutoutFromWall fail?

 

3. I am trying to understand why SpatialElementGeometryCalculator does not calculate opening on the sample model. Therefore, i porting it over to python. As I am looking through the code, there is function that I am not sure how it suppose to work. Under this function GetWallProfilePolygons suppose to output variable Polygon, but I am not sure how does the polygon variable is updated by GetProfile as it only return boolean instead of polygon. Is it suppose to work like this? 

 

static public List<List<XYZ>> GetWallProfilePolygons( 
      List<Element> walls, 
      Options opt )
    {
      XYZ p, q, v, w;

      List<List<XYZ>> polygons = new List<List<XYZ>>();

      foreach( Wall wall in walls )
      {
        LocationCurve curve
          = wall.Location as LocationCurve;

        if( null == curve )
        {
          return null;
        }
        p = curve.Curve.GetEndPoint( 0 );
        q = curve.Curve.GetEndPoint( 1 );
        v = q - p;
        v = v.Normalize();
        w = XYZ.BasisZ.CrossProduct( v ).Normalize();

        if( wall.Flipped ) { w = -w; }

        GeometryElement geo = wall.get_Geometry( opt );

        foreach( GeometryObject obj in geo )
        {
          Solid solid = obj as Solid;
          if( solid != null )
          {
            GetProfile( polygons, solid, v, w );
          }
        }
      }
      return polygons;
    }

 

 4. There is another opening like "Rectangular Straight Wall Opening" wouldn't be calculated by the code I assume. I wondering is there anyway to calculate area of opening correctly

0 Likes
706 Views
1 Reply
Reply (1)
Message 2 of 2

yjeugene888
Explorer
Explorer

I manage to figure out the first one. DirectShape.SetShape() requires Argument to be enumerable. In that code,  i only port into array

0 Likes