Say we have some 3D solid parts and we want to automatically replace them all with free standing point masses using scripting?
The below sample does a bit of this (loops through gets flexible 3D solids, and replaces them with a point mass).
model = ExtAPI.DataModel.Project.Model
Parts = model.Geometry.GetChildren(DataModelObjectCategory.Part,True) # get all parts
SlMn = ExtAPI.SelectionManager SlMn.ClearSelection() Sel = SlMn.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
for Part in Parts: # loop over parts for Body in Part.Children: if (Body.GeometryType)==(GeometryType.Solid) and (Body.StiffnessBehavior)==(StiffnessBehavior.Flexible): #Body.StiffnessBehavior=StiffnessBehavior.Rigid Mass=(Body.Mass.Value) #add other properties rp=model.AddRemotePoint() rp.ScopingMethod=GeometryDefineByType.FreeStanding rp.XCoordinate=Body.CentroidX rp.YCoordinate=Body.CentroidY rp.ZCoordinate=Body.CentroidZ rm=model.Geometry.AddPointMass() rm.AppliedBy=RemoteApplicationType.RemoteAttachment rm.Location = rp rm.Mass=Body.Mass rm.MassMomentOfInertiaX=treebody.MomentOfInertiaIp1 rm.MassMomentOfInertiaY=treebody.MomentOfInertiaIp2 rm.MassMomentOfInertiaZ=treebody.MomentOfInertiaIp3 Body.Suppressed=True SlMn.ClearSelection() Tree.Refresh()
Or if we want to loop through all parts in a current selection and convert them then the below helps:
SlMn = ExtAPI.SelectionManager Sel=SlMn.CurrentSelection
for s in Sel: geobody=ExtAPI.DataModel.GeoData.GeoEntityById(Sel.Ids[0]) treebody=treebody=ExtAPI.DataModel.Project.Model.Geometry.GetBody(geobody) rm=model.Geometry.AddPointMass() rm.Mass=treebody.Mass rm.XCoordinate=treebody.CentroidX rm.YCoordinate=treebody.CentroidY rm.ZCoordinate=treebody.CentroidZ rm.MassMomentOfInertiaX=treebody.MomentOfInertiaIp1 rm.MassMomentOfInertiaY=treebody.MomentOfInertiaIp2 rm.MassMomentOfInertiaZ=treebody.MomentOfInertiaIp3 treebody.Suppressed=True SlMn.ClearSelection() Tree.Refresh()