IFC Python Question (continued from old forum)

hi @johnmirts , i guess that the old python example you posted a while ago is not working with the your current IFC library.

I tried to adapt it to the current version of the library without success.
I was able to output what it looks an express code, but no ifc viewer is capable of interpret this…
Some working example for python with the currect IFC library version would be much appreciated.


    import clr
    import sys
    #sys.path.append(r"C:\Program Files (x86)\Geometry Gym\Rhino3d")

    #clr.AddReference("ggRhinoIFC.dll")
    clr.AddReferenceToFileAndPath(r"C:\Users\aleceta\Source\Repos\GeometryGymIFC\DLL Projects\GeometryGymIFCRhinoCommonx64\bin\GeometryGymIFCRhinoCommonx64.dll")


    import GeometryGym.Ifc as gg 


    from System.Collections.Generic import List
    from System import Guid
    from Rhino.Geometry import Transform
    from Rhino.Geometry import Point3d
    from Rhino.Geometry import Vector3d
    from Rhino.Geometry import Line
    from Rhino.Geometry import Plane

    ipe = "IPE300"
    db = gg.DatabaseIfc(True,gg.ModelView.Ifc2x3Coordination) 

    building = gg.IfcBuilding(db,"PythonBuilding")
    project = gg.IfcProject(db,"PythonProject")
    s355 = gg.IfcMaterial(db,"S355JR") 
    s355.Category = "STEEL"
    pd = gg.IfcIShapeProfileDef(db,ipe,300,150,7.1,10.7,15)
    #ifcBeamTypeID = GuidEncoder.Encode(Guid("{FA07940E-19FC-417a-B7F1-09A0CCF39B74}")) 
    #Can create a unique identifier if you wish else leave blank
    mp = gg.IfcMaterialProfile(ipe,s355,pd)
    mpUsage = gg.IfcMaterialProfileSetUsage(mp)
    #bt = gg.IfcBeamType(ipe,mp,gg.IfcBeamTypeEnum.BEAM)
    ln = Line(Point3d(0,0,0),Point3d(1,0,0)) #use SI units ie metres
    clipPlanes = List[Plane]()

    #beam = gg.IfcBeamStandardCase(building,bt,ln,Vector3d.YAxis, gg.IfcCardinalPointReference.MID,clipPlanes)
    axisPlacement = gg.IfcAxis2Placement3D(gg.IfcCartesianPoint(db,0,0,0),gg.IfcDirection(db,0,1,0),gg.IfcDirection(db,0,0,1))
    beam = gg.IfcBeamStandardCase(building,mpUsage,axisPlacement,10)
    a = db.ToString()
    gg.DatabaseIfc.WriteFile(db,'testFile')

Hi @aitorleceta,

Thanks for posting. I’ve neglected the iron python interaction a bit, and I’ve changed quite a bit of the code.
I’ve modified your script in a few ways (but you were very close). First, I included the building object into the constructor for the project (else the project hierarchy isn’t set). I also set units to millimetres (originally all units of the IFC from my toolkit was metres). I adjusted a couple of other things, if you’re using the open source toolkit from github, there is a branch with latest live code (which will be consistent with the latest rhino plugin).


Download the latest ifc plugin from http://www.geometrygym.com/downloads to work with this version of the script if you don’t change my reference to the dll.

Let me know if this helps or not.

Cheers,

Jon (ps, mark posts attention to @jonm, not sure who it is you tagged in your post).

180508 python script.gh (11.7 KB)

1 Like