rdmax 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rdmax/modeling.py ADDED
@@ -0,0 +1,1674 @@
1
+ """RecurDyn modeling helper (split from RDFunctions.py)."""
2
+
3
+ from rdmax._common import * # noqa: F401,F403
4
+ from rdmax.utils import unique_geo_name, subsystem_list_full
5
+
6
+ __all__ = ['RecurDynModeling']
7
+
8
+ class RecurDynModeling:
9
+ verbose = False
10
+ orientation_type = EulerAngle.EulerAngle_ZYX
11
+ ColorIn = Color.Yellow
12
+ MeshMode = None
13
+
14
+ def __init__(self, ver=RECURDYN_VERSION, rdyn_path=None):
15
+ print("[ RDFunctions version " + str(ver) + " ]")
16
+ # set_recurdyn_api_path(ver)
17
+ self.rd_ver = ver
18
+ # set_rd_lib_path(self.rd_ver)
19
+ self.application = IApplication(dispatch_recurdyn(self.rd_ver, True, 300).RecurDynApplication)
20
+ # print("PNet Version: " + self.application.ProcessNetVersion)
21
+ if rdyn_path is None:
22
+ self.modelDocument = self.application.ActiveModelDocument
23
+ if self.modelDocument is None:
24
+ self.modelDocument = self.application.NewModelDocument('Model1')
25
+ else:
26
+ # rdyn_file_name = str(Path(rdyn_path).name) # rdyn file name only
27
+ rdyn_name = str(Path(rdyn_path).stem) # rdyn name only
28
+ self.modelDocument = self.application.GetModelDocument(rdyn_name)
29
+ if self.modelDocument is None:
30
+ if Path(rdyn_path).is_file():
31
+ self.modelDocument = self.application.OpenModelDocument(Path(rdyn_path).absolute())
32
+ self.application.PrintMessage(rdyn_name + ' is loaded')
33
+ print(rdyn_name + '.rdyn is loaded')
34
+ else:
35
+ self.modelDocument = self.application.NewModelDocument(rdyn_name)
36
+ self.modelDocument.FileSave(rdyn_path, True)
37
+ self.application.PrintMessage(rdyn_name + ' is created')
38
+ print(rdyn_name + '.rdyn is created')
39
+ self.modelDocument = self.application.ActiveModelDocument
40
+ self.modelDocument = IModelDocument(self.modelDocument)
41
+ self.working_directory = self.modelDocument.GetPath(PathType.WorkingFolder)
42
+ self.model = ISubSystem(self.modelDocument.Model)
43
+ self.rdyn_path = self.modelDocument.GetPath(PathType.WorkingDocument)
44
+ self.reframe = IReferenceFrame(self.modelDocument.CreateReferenceFrame())
45
+ self.reframe1 = IReferenceFrame(self.modelDocument.CreateReferenceFrame())
46
+ self.reframe2 = IReferenceFrame(self.modelDocument.CreateReferenceFrame())
47
+ self.update_reframe(self.reframe)
48
+ self.update_reframe(self.reframe1)
49
+ self.update_reframe(self.reframe2)
50
+ self.Subsystems = subsystem_list_full(self.model)
51
+ import recurdyn.ExternalSPI as ExtSPI
52
+ try:
53
+ self.ExtSPI = ExtSPI.IExternalSPIToolkit(self.model.ExternalSPIToolkit)
54
+ self.ExtSPI.Program = 'Particleworks'
55
+ except:
56
+ pass
57
+
58
+ def Dispose(self):
59
+ # Redraw() and UpdateDatabaseWindow() can take more time in a heavy model.
60
+ self.modelDocument.Redraw()
61
+ # model_document.PostProcess() # UpdateDatabaseWindow(), SetModified()
62
+ self.modelDocument.UpdateDatabaseWindow()
63
+ # If you call SetModified(), Animation will be reset.
64
+ self.modelDocument.SetModified()
65
+ self.modelDocument.SetUndoHistory("Python ProcessNet")
66
+
67
+ def PrintMsg(self, msg):
68
+ self.application.PrintMessage(msg)
69
+
70
+ def OpenModelDocument(self, rdyn_path):
71
+ if Path(rdyn_path).is_file():
72
+ self.modelDocument = self.application.OpenModelDocument(Path(rdyn_path).absolute())
73
+ self.working_directory = self.modelDocument.GetPath(PathType.WorkingFolder)
74
+ self.model = ISubSystem(self.modelDocument.Model)
75
+
76
+ def update_reframe(self, reframe, pos=(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)):
77
+ # position and posture
78
+ reframe.SetOrigin(pos[0], pos[1], pos[2])
79
+ if len(pos) == 6:
80
+ reframe.SetEulerAngleDegree(self.orientation_type, pos[3], pos[4], pos[5])
81
+
82
+ def ParameterizeReframe(self, reframe, PP1, Dir1=AxisType.PlusX, PP2=None, Dir2=AxisType.PlusY, PP3=None):
83
+ reframe = IReferenceFrame(reframe)
84
+ reframe.Origin.ParametricPoint = IParametricPoint(PP1)
85
+ if PP2 is not None and PP3 is not None:
86
+ reframe.OrientationType = OrientationType.CartesianCoordinate
87
+ reframe.PrimaryPointType = Dir1
88
+ reframe.PrimaryPoint.ParametricPoint = PP2
89
+ reframe.SecondaryPointType = Dir2
90
+ reframe.SecondaryPoint.ParametricPoint = PP3
91
+
92
+ def SetWorkingPlane(self, plane="XZ"):
93
+ if plane == "XY":
94
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneXY)
95
+ elif plane == "YX":
96
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneYX)
97
+ elif plane == "YZ":
98
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneYZ)
99
+ elif plane == "ZY":
100
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneZY)
101
+ elif plane == "XZ":
102
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneXZ)
103
+ else:
104
+ self.modelDocument.ChangeWorkingPlane2(WorkingPlaneType2.PlaneZX)
105
+
106
+ def SetupCustomRecurdyn(self, gravity=(0.0, -9806.65, 0.0)):
107
+ self.modelDocument.ModelSetting.ModelSettingGeneral.ShiftWhenPasting = False
108
+ self.modelDocument.ModelSetting.ModelSettingGeneral.AccelerateRenderingWhenControllingView = False
109
+ self.modelDocument.ModelSetting.ModelSettingGeneral.AutofitAfterChangeOfWorkingWindow = False
110
+ self.modelDocument.ModelSetting.ModelSettingGeneral.CreateBackupFile = False
111
+
112
+ # Working Plane Setting
113
+ self.modelDocument.ChangeWorkingPlane2( WorkingPlaneType2.PlaneXZ )
114
+ self.modelDocument.ChangeWorkingPlane(WorkingPlaneType.Front)
115
+ # Gravity Settings------------------------------------------------------------------------------------------------
116
+ if gravity:
117
+ self.modelDocument.ModelProperty.UseGravity = True
118
+ self.modelDocument.ModelProperty.GravityX = gravity[0]
119
+ self.modelDocument.ModelProperty.GravityY = gravity[1]
120
+ self.modelDocument.ModelProperty.GravityZ = gravity[2]
121
+ # Display Settings------------------------------------------------------------------------------------------------
122
+ self.modelDocument.ModelSetting.ModelSettingDisplay.FontSize = 12
123
+ self.modelDocument.ModelSetting.ModelSettingDisplay.ErrorTolerance = 1e-12
124
+ self.modelDocument.ModelSetting.ModelSettingDisplay.ShowContactSurfaceNormalDirection = True
125
+ self.modelDocument.ModelSetting.ModelSettingDisplay.ContractSurfaceNormalDirectionValue = 10
126
+ self.application.Settings.ShiftWhenPasting = False
127
+ self.modelDocument.ModelSetting.ModelSettingDisplay.HideInactiveEntity = False
128
+ self.modelDocument.ModelSetting.ModelSettingDisplay.AlignCenterMarkerOrientationWithBodyPrincipalAxis = False
129
+ self.modelDocument.ModelSetting.ModelSettingDisplay.AccelerateRenderingInViewControl = False
130
+ self.modelDocument.ModelSetting.ModelSettingDisplay.AutoFitWhenChangingWorkingPlane = False
131
+ self.modelDocument.ModelSetting.ModelSettingDisplay.UseTransparentBackgroundOfTooltipBox = False
132
+ self.application.Settings.LinearSolverTypeForMBD = LinearSolverTypeForMBD.LinearSolverTypeForMBD_Auto
133
+
134
+ # self.modelDocument.ModelSetting.ModelSettingDisplay.UseWindowsAero = True
135
+ # Flexibility Settings------------------------------------------------------------------------------------------------
136
+ self.modelDocument.ModelSetting.Flexibility.FFlex.CoreOption = Core_Option.In_Core
137
+ self.modelDocument.ModelSetting.Flexibility.FFlex.StressRecoveryType = StressRecoveryType.RecoveryType_Extrapolation
138
+ self.modelDocument.ModelSetting.Flexibility.FFlex.AutomaticOutputsforMarkers = True
139
+ self.modelDocument.ModelSetting.Flexibility.RFlex.MaxNoOfInterfaceNodeMarkers = 300
140
+ self.modelDocument.ModelSetting.Flexibility.RFlex.AutomaticOutputsforMarkers = True
141
+ self.modelDocument.ModelSetting.Flexibility.RFlex.MassInvariant = MassInvariantType.MassInvariantType_BodySetting
142
+ self.modelDocument.ModelSetting.Flexibility.RFlex.RedundantCheck = RedundantCheckType.RedundantCheckType_Once
143
+ # Simulation Settings------------------------------------------------------------------------------------------------
144
+ # Tab1 General
145
+ self.application.Settings.AutoCoreNumber = False
146
+ self.application.Settings.CoreNumber2 = CoreType.Num4
147
+ self.application.Settings.SolverType = ModelSettingSimulationSolverType.SimulationSolverType_DLL
148
+ self.application.Settings.LinearSolverTypeForMBD = LinearSolverTypeForMBD.LinearSolverTypeForMBD_Auto
149
+ self.application.Settings.InitialVelocity = InitialVelocityType.InitialVelocityType_Relative
150
+ self.application.Settings.CheckRedundantType = CheckRedundantType.CheckRedundantType_EveryStep
151
+ self.application.Settings.SaveBeforSimulation = True
152
+ self.application.Settings.SaveAfterSimulation = False
153
+ self.application.Settings.CreateBackupFile = False
154
+ self.application.Settings.UseJointPartition = False
155
+ self.application.Settings.CreateOutputFolder = False
156
+ self.application.Settings.ShowWarningMessage = False
157
+ self.application.Settings.StopRedundantConstraint = False
158
+ self.application.Settings.AdvancedControlForIntgratorFailure = True
159
+ self.application.Settings.UseRedundantConstraintCheckTolerance = False
160
+ self.application.Settings.RedundantConstraintCheckToleranceValue = 1.0e-4
161
+ self.application.Settings.UseRedundantViolationLengthTolerance = False
162
+ self.application.Settings.RedundantViolationLengthToleranceValue = 1.0e-3
163
+ self.application.Settings.UseRedundantViolationAngleTolerance = False
164
+ self.application.Settings.RedundantViolationAngleToleranceValue = 1.0e-3
165
+ self.application.Settings.UseAngleLimit = True
166
+ self.application.Settings.AngleLimit = 15.0
167
+ self.application.Settings.UseAdvancedAngleMeasureFor3DRotation = True
168
+ self.application.Settings.MaximumConvergenceCount = 3
169
+ self.application.Settings.MessageOutputFactor = 100
170
+ self.application.Settings.UseJacobianEvaluationInterval = False
171
+ self.application.Settings.JacobianEvaluationInterval = 1
172
+ self.application.Settings.UseImprovementPreAnalysisAccuracy = True
173
+ # Tab2 Output Files-----------------------------------------------------------------------------------------------
174
+ # Start & End Time for Output
175
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.UseOutputStartTime = False
176
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.UseOutputEndTime = False
177
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.OutputStartTime = 0.01
178
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.OutputEndTime = 0.0
179
+ # Message Setting
180
+ self.modelDocument.MessageFileSettings.AnalysisInformation = True
181
+ self.modelDocument.MessageFileSettings.AnalysisProcess = True
182
+ self.modelDocument.MessageFileSettings.ConstraintInformation = False
183
+ self.modelDocument.MessageFileSettings.ConstraintViolation = False
184
+ self.modelDocument.MessageFileSettings.IndependentCoordinate = False
185
+ self.modelDocument.MessageFileSettings.IntegratorInformation = True
186
+ self.modelDocument.MessageFileSettings.JointInformation = False
187
+ self.modelDocument.MessageFileSettings.ModelVerification = True
188
+ self.modelDocument.MessageFileSettings.RedundantConstraint = True
189
+ self.modelDocument.MessageFileSettings.SolverInformation = True
190
+ # Results Files
191
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRMD = True
192
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRAD = True
193
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRequest = False
194
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforDesignParameter = False
195
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforSolverGeneratedAnimation = True
196
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRPLT = True
197
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforOutput = False
198
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMessage = True
199
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforPerformanceIndex = False
200
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMultiOutput = False
201
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMCK = False
202
+ # Tab3--------------------------------------------------------------------------------------------------
203
+ # Dynamic Kinamatic Analysis
204
+ # Tab1 General
205
+ # self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationTime.Value = 1.0
206
+ # self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationStep.Value = 100
207
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.PlotMultiplierStepFactor.Value = 1
208
+ self.modelDocument.UseOutputFileName = True
209
+ self.modelDocument.OutputFileName = "SimResult\\" + self.modelDocument.Model.Name
210
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.IncludeStaticAnalysis = False
211
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.IncludeEigenValueAnalysis = False
212
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.IncludeStateMatrix = False
213
+ # Hide RecurDyn during Simulation
214
+ self.modelDocument.ModelSetting.DisplayAnimationDuringSimulation = True
215
+ # Tab2 Parameter
216
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.MaxTimeStep.Value = 1.0e-3
217
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.InitialTimeStep.Value = 1.0e-4
218
+ # self.modelDocument.ModelProperty.DynamicAnalysisProperty.ErrorTolerance.Value = 5.0e-3
219
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.IntegratorType = IntegratorType.ADVHYBRID
220
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.NumericalDamping.Value = 1.0
221
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.JacobianEvaluation.Value = 100
222
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.MatchSolvingStepSize = False
223
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.MatchSimulationEndTime = True
224
+ # Tab3 initial Condition
225
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.CreateInitialConditionEveryStep = False
226
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.CreateInitialConditionPlotStep = False
227
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.ICFCreationTypePlotStep = ICFCreationType.ICFCreationType_RECENT
228
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.ExpressionTimeOffset = True
229
+ # Model Settings
230
+ self.modelDocument.ModelSetting.IconSize = 20
231
+ self.modelDocument.ModelSetting.MarkerSize = 20
232
+ self.modelDocument.ModelSetting.ForceDisplayScale = 1.0
233
+ self.modelDocument.ModelSetting.ForceDisplayWidth = 1.0
234
+ self.modelDocument.ModelSetting.ShowIconAll = True
235
+ self.modelDocument.ModelSetting.ShowMarkerCenter = False
236
+ self.modelDocument.ModelSetting.ShowLight = False
237
+ self.modelDocument.ModelSetting.AnimationControl.UseUserDefinedAnimation = True
238
+ self.modelDocument.ModelSetting.AnimationControl.DisplayMarkers = True
239
+ # Model Display Name Change
240
+ self.modelDocument.Model.Name = self.modelDocument.Name.replace(".rdyn", "")
241
+
242
+ def SetupCustomMessage(self):
243
+ self.modelDocument.MessageFileSettings.AnalysisInformation = True
244
+ self.modelDocument.MessageFileSettings.AnalysisProcess = True
245
+ self.modelDocument.MessageFileSettings.ConstraintInformation = False
246
+ self.modelDocument.MessageFileSettings.ConstraintViolation = False
247
+ self.modelDocument.MessageFileSettings.IndependentCoordinate = False
248
+ self.modelDocument.MessageFileSettings.IntegratorInformation = True
249
+ self.modelDocument.MessageFileSettings.JointInformation = False
250
+ self.modelDocument.MessageFileSettings.ModelVerification = True
251
+ self.modelDocument.MessageFileSettings.RedundantConstraint = True
252
+ self.modelDocument.MessageFileSettings.SolverInformation = True
253
+
254
+ def SetupCustomOutput(self):
255
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRMD = True
256
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRAD = True
257
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRequest = False
258
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforDesignParameter = False
259
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforSolverGeneratedAnimation = True
260
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRPLT = True
261
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforOutput = False
262
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMessage = True
263
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforPerformanceIndex = False
264
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMultiOutput = False
265
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforMCK = False
266
+
267
+ def SetupCustomRegenerator(self):
268
+ regenerator = IFFlexOutputFileRegenerator(IFFlexToolkit(self.model.FFlexToolkit).OutputFileRegenerator)
269
+ regenerator.SameOptionsforAllFFlexBodies = True
270
+ regenerator.RecoverData = False
271
+ regenerator.OutputFileSetting.ClearCheckStrain()
272
+ regenerator.OutputFileSetting.ClearCheckStress()
273
+ regenerator.OutputFileSetting.SMISES = True
274
+ regenerator.OutputFileSetting.DataPrecision = StrainStressDataPrecision.DataPrecision_Float
275
+ regenerator = IRFlexOutputFileRegenerator(IRFlexToolkit(self.model.RFlexToolkit).OutputFileRegenerator)
276
+ regenerator.SameOptionsforAllRFlexBodies = True
277
+ regenerator.OutputFileSetting.ClearCheckStrain()
278
+ regenerator.OutputFileSetting.ClearCheckStress()
279
+ regenerator.OutputFileSetting.SMISES = True
280
+ regenerator.OutputFileSetting.DataPrecision = StrainStressDataPrecision.DataPrecision_Float
281
+
282
+ def ChangeDataStorage(self, entity_name=None, fullname=False ):
283
+ if fullname:
284
+ entity = self.modelDocument.Model.GetEntity(entity_name)
285
+ else:
286
+ entity = self.model.GetEntity(entity_name)
287
+ type_str = get_type(entity, False)
288
+ # print(type_str)
289
+ if type_str == "ISubSystem":
290
+ self.modelDocument.ChangeDataStorage(entity)
291
+ self.model = ISubSystem(entity)
292
+ if self.verbose: print("Database is changed to Subsystem(" + entity_name + ")")
293
+ self.subsystem = ISubSystem(entity)
294
+ elif type_str == "IBody":
295
+ self.modelDocument.ChangeDataStorage(entity)
296
+ if self.verbose: print("Database is changed to Body(" + entity_name + ")")
297
+ self.body = IBody(entity)
298
+ elif entity_name == None:
299
+ self.model = self.modelDocument.Model
300
+ self.modelDocument.ChangeDataStorage(self.model)
301
+ if self.verbose: print("Database is changed to top model")
302
+ else:
303
+ if self.verbose: print("Invalid Database storage name: " + entity_name)
304
+ return None
305
+ return entity
306
+
307
+ def ReturnDataStorage(self):
308
+ self.modelDocument.ChangeDataStorage(self.model.OwnerSubSystem)
309
+ self.model = ISubSystem(self.model.OwnerSubSystem)
310
+
311
+ def CreateINFPP(self):
312
+ PPX = self.model.GetEntity("INFX")
313
+ if PPX is None:
314
+ PPX = self.model.CreateParametricPoint("INFX", [1e20, 0.0, 0.0], None)
315
+ PPY = self.model.GetEntity("INFY")
316
+ if PPY is None:
317
+ PPY = self.model.CreateParametricPoint("INFY", [0.0, 1e20, 0.0], None)
318
+ PPZ = self.model.GetEntity("INFZ")
319
+ if PPZ is None:
320
+ PPZ = self.model.CreateParametricPoint("INFZ", [0.0, 0.0, 1e20], None)
321
+ return IParametricPoint(PPX), IParametricPoint(PPY), IParametricPoint(PPZ)
322
+
323
+ def CopyReframeToReframe(self, from_reframe, to_reframe):
324
+ self.CopyReframeToReframePosition(from_reframe, to_reframe)
325
+ self.CopyReframeToReframeOrientation(from_reframe, to_reframe)
326
+
327
+ def CopyReframeToReframePosition(self, from_reframe, to_reframe):
328
+ from_reframe = IReferenceFrame(from_reframe)
329
+ to_reframe = IReferenceFrame(to_reframe)
330
+ # Copy Position
331
+ if from_reframe.Origin.ParametricPoint == None:
332
+ to_reframe.SetOrigin(from_reframe.Origin.x, from_reframe.Origin.y, from_reframe.Origin.z)
333
+ else:
334
+ to_reframe.Origin.ParametricPoint = from_reframe.Origin.ParametricPoint
335
+
336
+ def CopyReframeToReframeOrientation(self, from_reframe, to_reframe):
337
+ from_reframe = IReferenceFrame(from_reframe)
338
+ to_reframe = IReferenceFrame(to_reframe)
339
+ # Copy Orientation
340
+ if from_reframe.OrientationType == OrientationType.CartesianCoordinate:
341
+ to_reframe.OrientationType = OrientationType.CartesianCoordinate
342
+ to_reframe.PrimaryPointType = from_reframe.PrimaryPointType
343
+ if from_reframe.PrimaryPoint.ParametricPoint != None:
344
+ to_reframe.PrimaryPoint.ParametricPoint = from_reframe.PrimaryPoint.ParametricPoint
345
+ else:
346
+ to_reframe.PrimaryPoint.x = from_reframe.PrimaryPoint.x
347
+ to_reframe.PrimaryPoint.y = from_reframe.PrimaryPoint.y
348
+ to_reframe.PrimaryPoint.z = from_reframe.PrimaryPoint.z
349
+ to_reframe.SecondaryPointType = from_reframe.SecondaryPointType
350
+ if from_reframe.SecondaryPoint.ParametricPoint != None:
351
+ to_reframe.SecondaryPoint.ParametricPoint = from_reframe.SecondaryPoint.ParametricPoint
352
+ else:
353
+ to_reframe.SecondaryPoint.x = from_reframe.SecondaryPoint.x
354
+ to_reframe.SecondaryPoint.y = from_reframe.SecondaryPoint.y
355
+ to_reframe.SecondaryPoint.z = from_reframe.SecondaryPoint.z
356
+ else:
357
+ to_reframe.EulerAngle.Type = from_reframe.EulerAngle.Type
358
+ if from_reframe.EulerAngle.Alpha.ParametricValue != None:
359
+ to_reframe.EulerAngle.Alpha.ParametricValue = from_reframe.EulerAngle.Alpha.ParametricValue
360
+ else:
361
+ to_reframe.EulerAngle.Alpha.Value = from_reframe.EulerAngle.Alpha.Value
362
+ if from_reframe.EulerAngle.Beta.ParametricValue != None:
363
+ to_reframe.EulerAngle.Beta.ParametricValue = from_reframe.EulerAngle.Beta.ParametricValue
364
+ else:
365
+ to_reframe.EulerAngle.Beta.Value = from_reframe.EulerAngle.Beta.Value
366
+ if from_reframe.EulerAngle.Gamma.ParametricValue != None:
367
+ to_reframe.EulerAngle.Gamma.ParametricValue = from_reframe.EulerAngle.Gamma.ParametricValue
368
+ else:
369
+ to_reframe.EulerAngle.Gamma.Value = from_reframe.EulerAngle.Gamma.Value
370
+
371
+ def CreateBodyCylinder(self, body_name, radius, height, pos=None):
372
+ if pos is not None: self.update_reframe(self.reframe, pos)
373
+ body = self.model.GetEntity(body_name)
374
+ if body:
375
+ self.modelDocument.DeleteEntity(body)
376
+ body = self.model.CreateBodyCylinder(body_name, self.reframe, radius, height)
377
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
378
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
379
+ return IBody(body), IGeometryCylinder(body.GetEntity("Cylinder1"))
380
+
381
+ def UseBodyCylinder(self, body_name, radius, height, pos=None):
382
+ if pos is not None: self.update_reframe(self.reframe, pos)
383
+ body = self.model.GetEntity(body_name)
384
+ if body:
385
+ body = IBody(body)
386
+ cylinder_name = unique_geo_name(body, "Cylinder")
387
+ body.CreateCylinderGeometry(cylinder_name, self.reframe, radius, height)
388
+ else:
389
+ body = self.model.CreateBodyCylinder(body_name, self.reframe, radius, height)
390
+ cylinder_name = "Cylinder1"
391
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
392
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
393
+ return IBody(body), IGeometryCylinder(body.GetEntity(cylinder_name))
394
+
395
+ def CreateBodyEllipsoid(self, body_name, radius=100, pos=None):
396
+ if pos is not None: self.update_reframe(self.reframe, pos)
397
+ body = self.model.GetEntity(body_name)
398
+ if body:
399
+ self.modelDocument.DeleteEntity(body)
400
+ body = self.model.CreateBodyEllipsoid(body_name, self.reframe, radius, radius, radius)
401
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
402
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
403
+ return IBody(body), IGeometrySphere(body.GetEntity("Ellipsoid1"))
404
+
405
+ def UseBodyEllipsoid(self, body_name, radius, pos=None):
406
+ if pos is not None: self.update_reframe(self.reframe, pos)
407
+ body = self.model.GetEntity(body_name)
408
+ if body:
409
+ body = IBody(body)
410
+ Elipsoid_name = unique_geo_name(body, "Elipsoid")
411
+ body.CreateEllipsoidGeometry(Elipsoid_name, self.reframe, radius, radius, radius)
412
+ else:
413
+ body = self.model.CreateBodyEllipsoid(body_name, self.reframe, radius, radius, radius)
414
+ Elipsoid_name = "Ellipsoid1"
415
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
416
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
417
+ return IBody(body), IGeometrySphere(body.GetEntity(Elipsoid_name))
418
+
419
+ def CreateBodyBox(self, body_name, width=100, height=100, depth=100, pos=None):
420
+ if pos is not None: self.update_reframe(self.reframe, pos)
421
+ body = self.model.GetEntity(body_name)
422
+ if body:
423
+ self.modelDocument.DeleteEntity(body)
424
+ body = self.model.CreateBodyBox(body_name, self.reframe, width, height, depth)
425
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
426
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
427
+ return IBody(body), IGeometryBox(body.GetEntity("Box1"))
428
+
429
+ def UseBodyBox(self, body_name, width, height, depth, pos=None):
430
+ if pos is not None: self.update_reframe(self.reframe, pos)
431
+ body = self.model.GetEntity(body_name)
432
+ if body:
433
+ body = IBody(body)
434
+ box_name = unique_geo_name(body, "Box")
435
+ body.CreateBoxGeometry(box_name, self.reframe, width, height, depth)
436
+ else:
437
+ body = self.model.CreateBodyBox(body_name, self.reframe, width, height, depth)
438
+ box_name = "Box1"
439
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
440
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
441
+ return IBody(body), IGeometryBox(body.GetEntity(box_name))
442
+
443
+ def CreateBodyPrism(self, body_name, radius, height, nside, pos=None):
444
+ if pos is not None: self.update_reframe(self.reframe, pos)
445
+ body = self.model.GetEntity(body_name)
446
+ if body:
447
+
448
+ self.modelDocument.DeleteEntity(body)
449
+ body = self.model.CreateBodyPrism(body_name, self.reframe, radius, height, nside)
450
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
451
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
452
+ return IBody(body), IGeometryPrism(body.GetEntity("Prism1"))
453
+
454
+ def UseBodyPrism(self, body_name, radius, height, nside, pos=None):
455
+ if pos is not None: self.update_reframe(self.reframe, pos)
456
+ body = self.model.GetEntity(body_name)
457
+ if body:
458
+ body = IBody(body)
459
+ prism_name = unique_geo_name(body, "Prism")
460
+ body.CreatePrismGeometry(prism_name, self.reframe, radius, height, nside)
461
+ else:
462
+ body = self.model.CreateBodyPrism(body_name, self.reframe, radius, height, nside)
463
+ prism_name = "Prism1"
464
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
465
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
466
+ return IBody(body), IGeometryPrism(body.GetEntity(prism_name))
467
+
468
+ def CreateBodyTorus(self, body_name, majorR, minorR, pos=None):
469
+ if pos is not None: self.update_reframe(self.reframe, pos)
470
+ body = self.model.GetEntity(body_name)
471
+ if body:
472
+ self.modelDocument.DeleteEntity(body)
473
+ body = self.model.CreateBodyTorus(body_name, self.reframe, majorR, minorR)
474
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
475
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
476
+ return IBody(body), IGeometryTorus(body.GetEntity("Torus1"))
477
+
478
+ def UseBodyTorus(self, body_name, majorR, minorR, pos=None):
479
+ if pos is not None: self.update_reframe(self.reframe, pos)
480
+ body = self.model.GetEntity(body_name)
481
+ if body:
482
+ body = IBody(body)
483
+ torus_name = unique_geo_name(body, "Torus")
484
+ body.CreateTorusGeometry(torus_name, self.reframe, majorR, minorR)
485
+ else:
486
+ body = self.model.CreateBodyTorus(body_name, self.reframe, majorR, minorR)
487
+ torus_name = "Torus1"
488
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
489
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
490
+ return IBody(body), IGeometryTorus(body.GetEntity(torus_name))
491
+
492
+ def CreateBodyCone(self, body_name, topR, btmR, height, pos=None):
493
+ if pos is not None: self.update_reframe(self.reframe, pos)
494
+ body = self.model.GetEntity(body_name)
495
+ if body:
496
+ self.modelDocument.DeleteEntity(body)
497
+ body = self.model.CreateBodyCone(body_name, [0, 0, 0], [100, 0, 0], topR, btmR)
498
+ congeo = IGeometryCone(body.GetEntity("Cone1"))
499
+ congeo.RefFrame.SetOrigin(self.reframe.Origin.x, self.reframe.Origin.y, self.reframe.Origin.z)
500
+ congeo.RefFrame.SetEulerAngle(self.reframe.EulerAngle.Type,
501
+ self.reframe.EulerAngle.Alpha.Value,
502
+ self.reframe.EulerAngle.Beta.Value,
503
+ self.reframe.EulerAngle.Gamma.Value)
504
+ congeo.Height.Value = height
505
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
506
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
507
+ IBody(body).Redraw()
508
+ return IBody(body), IGeometryCone(congeo)
509
+
510
+ def UseBodyCone(self, body_name, topR, btmR, height, pos=None):
511
+ if pos is not None: self.update_reframe(self.reframe, pos)
512
+ body = self.model.GetEntity(body_name)
513
+ if body:
514
+ body = IBody(body)
515
+ cone_name = unique_geo_name(body, "Cone")
516
+ congeo = body.CreateConeGeometry(cone_name, [0, 0, 0], [100, 0, 0], topR, btmR)
517
+ else:
518
+ body = self.model.CreateBodyCone(body_name, [0, 0, 0], [100, 0, 0], topR, btmR)
519
+ congeo = IGeometryCone(body.GetEntity("Cone1"))
520
+ self.reframe = IReferenceFrame(self.reframe)
521
+ congeo.RefFrame.SetOrigin(self.reframe.Origin.x, self.reframe.Origin.y, self.reframe.Origin.z)
522
+ congeo.RefFrame.SetEulerAngle(self.reframe.EulerAngle.Type, self.reframe.EulerAngle.Alpha.Value,
523
+ self.reframe.EulerAngle.Beta.Value, self.reframe.EulerAngle.Gamma.Value)
524
+ congeo.Height.Value = height
525
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
526
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
527
+ IBody(body).Redraw()
528
+ return IBody(body), IGeometryCone(congeo)
529
+
530
+ def CreateBodyLink(self, body_name, pt1, pt2, pt1R, pt2R, depth, normal=None):
531
+ body = self.model.GetEntity(body_name)
532
+ if body:
533
+ self.modelDocument.DeleteEntity(body)
534
+ body = self.model.CreateBodyLinkWithRadius(body_name, pt1, pt2, pt1R, pt2R, depth)
535
+ link_geo = IGeometryLink(body.GetEntity("Link1"))
536
+ if normal is not None:
537
+ link_geo.SetNormalDirection(normal[0], normal[1], normal[2])
538
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
539
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
540
+ IBody(body).Redraw()
541
+ return IBody(body), IGeometryLink(link_geo)
542
+
543
+ def UseBodyLink(self, body_name, pt1, pt2, pt1R, pt2R, depth, normal=None):
544
+ body = self.model.GetEntity(body_name)
545
+ if body:
546
+ body = IBody(body)
547
+ link_name = unique_geo_name(body, "Link")
548
+ link_geo = body.CreateLinkGeometryWithRadius(link_name, pt1, pt2, pt1R, pt2R, depth)
549
+ else:
550
+ body = self.model.CreateBodyLinkWithRadius(body_name, pt1, pt2, pt1R, pt2R, depth)
551
+ link_geo = body.GetEntity("Link1")
552
+ link_geo = IGeometryLink(link_geo)
553
+ if normal != None:
554
+ link_geo.SetNormalDirection(normal[0], normal[1], normal[2])
555
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
556
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
557
+ IBody(body).Redraw()
558
+ return IBody(body), IGeometryLink(link_geo)
559
+
560
+ def CreateBodyGeneral(self, body_name):
561
+ body = self.model.GetEntity(body_name)
562
+ if body:
563
+ self.modelDocument.DeleteEntity(body)
564
+ body = self.model.CreateBodyGeneral(body_name)
565
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
566
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
567
+ IBody(body).Redraw()
568
+ return IBody(body)
569
+
570
+ def SetMassInertiaUserValue(self, body, mass=1, Ixx=1, Iyy=1, Izz=1, Ixy=0, Iyz=0, Izx=0):
571
+ body = IBody(body)
572
+ body.MaterialInput = MaterialInput.UserInput
573
+ body.Mass.Value = mass
574
+ body.Ixx.Value = Ixx
575
+ body.Iyy.Value = Iyy
576
+ body.Izz.Value = Izz
577
+ body.Ixy.Value = Ixy
578
+ body.Iyz.Value = Iyz
579
+ body.Izx.Value = Izx
580
+
581
+ def UseBodyGeneral(self, body_name):
582
+ body = self.model.GetEntity(body_name)
583
+ if body:
584
+ body = IBody(body)
585
+ else:
586
+ body = self.model.CreateBodyGeneral(body_name)
587
+ body.Graphic.Color = Color.rgb_to_bgr(self.ColorIn)
588
+ body.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
589
+ IBody(body).Redraw()
590
+ return IBody(body)
591
+
592
+ def UseBody(self, body_name):
593
+ body = self.model.GetEntity(body_name)
594
+ if body:
595
+ type_str = get_type(body, False)
596
+ if type_str == "IBody":
597
+ return IBody(body)
598
+ elif type_str == "IFFlexBody":
599
+ return IFFlexBody(body)
600
+ elif type_str == "IRFlexBody":
601
+ return IRFlexBody(body)
602
+ else:
603
+ body = self.model.CreateBodyGeneral(body_name)
604
+ return IBody(body)
605
+
606
+ def CreateMarker(self, mkr_name, body, pos=None):
607
+ if pos is not None: self.update_reframe(self.reframe, pos)
608
+ mkr = body.GetEntity(mkr_name)
609
+ if mkr is None:
610
+ mkr = body.CreateMarker(mkr_name, self.reframe)
611
+ return IMarker(mkr)
612
+
613
+ def CreateParametricMarker(self, mkr_name, pos=None, ref=None):
614
+ # if ref is None: ref = self.model.GetEntity(mkr_name)
615
+ mkr = self.model.GetEntity(mkr_name)
616
+ if mkr is None:
617
+ mkr = self.model.CreateParametricMarker(mkr_name, pos[0:2], ref)
618
+ mkr = IParametricMarker(mkr)
619
+ self.update_reframe(mkr.RefFrame, pos)
620
+ return IParametricMarker(mkr)
621
+
622
+ def UseMarker(self, mkr_name, body, pos=None):
623
+ if body is None:
624
+ print("body is not exist!")
625
+ return None
626
+ body = IBody(body)
627
+ mkr = body.GetEntity(mkr_name)
628
+ if mkr is None:
629
+ print("marker is not exist!")
630
+ return None
631
+ mkr = IMarker(mkr)
632
+ if pos is not None:
633
+ self.update_reframe(mkr.RefFrame, pos)
634
+ return IMarker(mkr)
635
+
636
+ def CreateJointFixed(self, entity_name, Bbody, Abody, pos=None):
637
+ if pos is not None: self.update_reframe(self.reframe, pos)
638
+ entity = self.model.GetEntity(entity_name)
639
+ if entity is not None:
640
+ self.modelDocument.DeleteEntity(entity)
641
+ entity = self.model.CreateJointFixedEx(entity_name, Bbody, Abody, self.reframe)
642
+ return IJointFixed(entity)
643
+
644
+ def UseJointFixed(self, entity_name, Bbody=None, Abody=None, pos=None):
645
+ entity = self.model.GetEntity(entity_name)
646
+ if entity is not None and Bbody is not None and Abody is not None:
647
+ entity = self.CreateJointFixed(entity_name, Bbody, Abody, pos=pos)
648
+ if entity is None:
649
+ raise ValueError(f"Entity not found: {entity_name}")
650
+ return IJointFixed(entity)
651
+
652
+ def CreateJointTranslational(self, entity_name, Bbody, Abody, pos=None):
653
+ if pos is not None: self.update_reframe(self.reframe, pos)
654
+ entity = self.model.GetEntity(entity_name)
655
+ if entity is not None:
656
+ self.modelDocument.DeleteEntity(entity)
657
+ entity = self.model.CreateJointTranslational(entity_name, Bbody, Abody, self.reframe)
658
+ return IJointTranslational(entity)
659
+
660
+ def UseJointTranslational(self, entity_name, Bbody=None, Abody=None, pos=None):
661
+ entity = self.model.GetEntity(entity_name)
662
+ if entity is not None and Bbody is not None and Abody is not None:
663
+ entity = self.CreateJointTranslational(entity_name, Bbody, Abody, pos=pos)
664
+ if entity is None:
665
+ raise ValueError(f"Entity not found: {entity_name}")
666
+ return IJointTranslational(entity)
667
+
668
+ def CreateJointCylindrical(self, entity_name, Bbody, Abody, pos=None):
669
+ if pos is not None: self.update_reframe(self.reframe, pos)
670
+ entity = self.model.GetEntity(entity_name)
671
+ if entity is not None:
672
+ self.modelDocument.DeleteEntity(entity)
673
+ entity = self.model.CreateJointCylindrical(entity_name, Bbody, Abody, self.reframe)
674
+ return IJointCylindrical(entity)
675
+
676
+ def UseJointCylindrical(self, entity_name, Bbody=None, Abody=None, pos=None):
677
+ entity = self.model.GetEntity(entity_name)
678
+ if entity is not None and Bbody is not None and Abody is not None:
679
+ entity = self.CreateJointCylindrical(entity_name, Bbody, Abody, pos=pos)
680
+ if entity is None:
681
+ raise ValueError(f"Entity not found: {entity_name}")
682
+ return IJointCylindrical(entity)
683
+
684
+ def CreateGeneralConstraint(self, entity_name, expression):
685
+ entity = self.model.GetEntity(entity_name)
686
+ if entity is not None:
687
+ self.modelDocument.DeleteEntity(entity)
688
+ entity = self.model.CreateGeneralConstraint(entity_name, expression)
689
+ return IGeneralConstraint(entity)
690
+
691
+ def CreateJointScrew(self, entity_name, Bbody, Abody, pitch, pos=None):
692
+ if pos is not None: self.update_reframe(self.reframe, pos)
693
+ entity = self.model.GetEntity(entity_name)
694
+ if entity is not None:
695
+ self.modelDocument.DeleteEntity(entity)
696
+ entity = self.model.CreateJointScrew(entity_name, Bbody, Abody, self.reframe, pitch)
697
+ return IJointScrew(entity)
698
+
699
+ def UseJointScrew(self, entity_name, Bbody=None, Abody=None, pitch=None, pos=None):
700
+ entity = self.model.GetEntity(entity_name)
701
+ if entity is not None and Bbody is not None and Abody is not None and pitch is not None:
702
+ entity = self.CreateJointScrew(entity_name, Bbody, Abody, pitch, pos=pos)
703
+ if entity is None:
704
+ raise ValueError(f"Entity not found: {entity_name}")
705
+ return IJointScrew(entity)
706
+
707
+ def CreateJointPlaner(self, entity_name, Bbody, Abody, pos=None):
708
+ if pos is not None: self.update_reframe(self.reframe, pos)
709
+ entity = self.model.GetEntity(entity_name)
710
+ if entity is not None:
711
+ self.modelDocument.DeleteEntity(entity)
712
+ entity = self.model.CreateJointPlanar(entity_name, Bbody, Abody, self.reframe)
713
+ return IJointPlanar(entity)
714
+
715
+ def UseJointPlaner(self, entity_name, Bbody=None, Abody=None, pos=None):
716
+ entity = self.model.GetEntity(entity_name)
717
+ if entity is not None and Bbody is not None and Abody is not None:
718
+ entity = self.CreateJointPlaner(entity_name, Bbody, Abody, pos=pos)
719
+ if entity is None:
720
+ raise ValueError(f"Entity not found: {entity_name}")
721
+ return IJointPlanar(entity)
722
+
723
+ def CreateJointRevolute(self, entity_name, Bbody, Abody, pos=None):
724
+ if pos is not None: self.update_reframe(self.reframe, pos)
725
+ entity = self.model.GetEntity(entity_name)
726
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
727
+ entity = self.model.CreateJointRevolute(entity_name, Bbody, Abody, self.reframe)
728
+ return IJointRevolute(entity)
729
+
730
+ def CreateJointCoupler(self, entity_name, BJoint, AJoint, scaleB=1, scaleA=1 ):
731
+ entity = self.model.GetEntity(entity_name)
732
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
733
+ entity = self.model.CreatePairConstraintCoupler(entity_name, BJoint, AJoint)
734
+ entity.DriverScale.Value = scaleB
735
+ entity.Coupler1Scale.Value = scaleA
736
+ return IJointRevolute(entity)
737
+
738
+ def UseJointCoupler(self, entity_name, scaleB=None, scaleA=None ):
739
+ entity = self.model.GetEntity(entity_name)
740
+ if entity is None:
741
+ raise ValueError(f"Entity not found: {entity_name}")
742
+ if scaleB is not None:
743
+ entity.DriverScale.Value = scaleB
744
+ if scaleA is not None:
745
+ entity.Coupler1Scale.Value = scaleA
746
+ return IJointRevolute(entity)
747
+ def UseJointRevolute(self, entity_name, Bbody=None, Abody=None, pos=None):
748
+ entity = self.model.GetEntity(entity_name)
749
+ if entity is not None and Bbody is not None and Abody is not None:
750
+ entity = self.CreateJointRevolute(entity_name, Bbody, Abody, pos=pos)
751
+ if entity is None:
752
+ raise ValueError(f"Entity not found: {entity_name}")
753
+ return IJointRevolute(entity)
754
+
755
+ def CreateJointSpherical(self, entity_name, Bbody, Abody, pos=None):
756
+ if pos is not None: self.update_reframe(self.reframe, pos)
757
+ entity = self.model.GetEntity(entity_name)
758
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
759
+ entity = self.model.CreateJointSpherical(entity_name, Bbody, Abody, self.reframe)
760
+ return IJointSpherical(entity)
761
+
762
+ def UseJointSpherical(self, entity_name, Bbody=None, Abody=None, pos=None):
763
+ entity = self.model.GetEntity(entity_name)
764
+ if entity is not None and Bbody is not None and Abody is not None:
765
+ entity = self.CreateJointSpherical(entity_name, Bbody, Abody, pos=pos)
766
+ if entity is None:
767
+ raise ValueError(f"Entity not found: {entity_name}")
768
+ return IJointSpherical(entity)
769
+
770
+ def CreateJointUniversal(self, entity_name, Bbody, Abody, pos1=None, pos2=None):
771
+ if pos1 != None: self.update_reframe(self.reframe1, pos1)
772
+ if pos2 != None: self.update_reframe(self.reframe2, pos2)
773
+ entity = self.model.GetEntity(entity_name)
774
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
775
+ entity = self.model.CreateJointUniversal(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
776
+ return IJointUniversal(entity)
777
+
778
+ def UseJointUniversal(self, entity_name, Bbody=None, Abody=None, pos1=None, pos2=None):
779
+ entity = self.model.GetEntity(entity_name)
780
+ if entity is not None and Bbody is not None and Abody is not None:
781
+ entity = self.CreateJointUniversal(entity_name, Bbody, Abody, pos1=pos1, pos2=pos2)
782
+ if entity is None:
783
+ raise ValueError(f"Entity not found: {entity_name}")
784
+ return IJointUniversal(entity)
785
+
786
+ def CreateJointConstantVelocity(self, entity_name, Bbody, Abody, pos1=None, pos2=None):
787
+ if pos1 != None: self.update_reframe(self.reframe1, pos1)
788
+ if pos2 != None: self.update_reframe(self.reframe2, pos2)
789
+ entity = self.model.GetEntity(entity_name)
790
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
791
+ entity = self.model.CreateJointConstantVelocity(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
792
+ return IJointConstantVelocity(entity)
793
+
794
+ def UseJointConstantVelocity(self, entity_name, Bbody=None, Abody=None, pos1=None, pos2=None):
795
+ entity = self.model.GetEntity(entity_name)
796
+ if entity is not None and Bbody is not None and Abody is not None:
797
+ entity = self.CreateJointConstantVelocity(entity_name, Bbody, Abody, pos1=pos1, pos2=pos2)
798
+ if entity is None:
799
+ raise ValueError(f"Entity not found: {entity_name}")
800
+ return IJointConstantVelocity(entity)
801
+
802
+ def CreateJointInline(self, entity_name, Bbody, Abody, pos=None):
803
+ if pos is not None: self.update_reframe(self.reframe, pos)
804
+ entity = self.model.GetEntity(entity_name)
805
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
806
+ entity = self.model.CreateJointInline(entity_name, Bbody, Abody, self.reframe, self.reframe)
807
+ return IJointInline(entity)
808
+
809
+ def UseJointInline(self, entity_name, Bbody=None, Abody=None, pos=None):
810
+ entity = self.model.GetEntity(entity_name)
811
+ if entity is not None and Bbody is not None and Abody is not None:
812
+ entity = self.CreateJointInline(entity_name, Bbody, Abody, pos=pos)
813
+ if entity is None:
814
+ raise ValueError(f"Entity not found: {entity_name}")
815
+ return IJointInline(entity)
816
+
817
+ def CreateJointInplane(self, entity_name, Bbody, Abody, pos=None):
818
+ if pos is not None: self.update_reframe(self.reframe, pos)
819
+ entity = self.model.GetEntity(entity_name)
820
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
821
+ entity = self.model.CreateJointInplane(entity_name, Bbody, Abody, self.reframe, self.reframe)
822
+ return IJointInplane(entity)
823
+
824
+ def UseJointInplane(self, entity_name, Bbody=None, Abody=None, pos=None):
825
+ entity = self.model.GetEntity(entity_name)
826
+ if entity is not None and Bbody is not None and Abody is not None:
827
+ entity = self.CreateJointInplane(entity_name, Bbody, Abody, pos=pos)
828
+ if entity is None:
829
+ raise ValueError(f"Entity not found: {entity_name}")
830
+ return IJointInplane(entity)
831
+
832
+ def CreateJointOrientation(self, entity_name, Bbody, Abody, pos=None):
833
+ if pos is not None: self.update_reframe(self.reframe, pos)
834
+ entity = self.model.GetEntity(entity_name)
835
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
836
+ entity = self.model.CreateJointOrientation(entity_name, Bbody, Abody, self.reframe)
837
+ return IJointOrientation(entity)
838
+
839
+ def UseJointOrientation(self, entity_name, Bbody=None, Abody=None, pos=None):
840
+ entity = self.model.GetEntity(entity_name)
841
+ if entity is not None and Bbody is not None and Abody is not None:
842
+ entity = self.CreateJointOrientation(entity_name, Bbody, Abody, pos=pos)
843
+ if entity is None:
844
+ raise ValueError(f"Entity not found: {entity_name}")
845
+ return IJointOrientation(entity)
846
+
847
+ def CreateJointParallel(self, entity_name, Bbody, Abody, pos1=None, pos2=None):
848
+ if pos1 != None: self.update_reframe(self.reframe1, pos1)
849
+ if pos2 != None: self.update_reframe(self.reframe2, pos2)
850
+ entity = self.model.GetEntity(entity_name)
851
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
852
+ entity = self.model.CreateJointParallel(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
853
+ return IJointParallel(entity)
854
+
855
+ def UseJointParallel(self, entity_name, Bbody=None, Abody=None, pos1=None, pos2=None):
856
+ entity = self.model.GetEntity(entity_name)
857
+ if entity is not None and Bbody is not None and Abody is not None:
858
+ entity = self.CreateJointParallel(entity_name, Bbody, Abody, pos1=pos1, pos2=pos2)
859
+ if entity is None:
860
+ raise ValueError(f"Entity not found: {entity_name}")
861
+ return IJointParallel(entity)
862
+
863
+ def CreateJointPerpendicular(self, entity_name, Bbody, Abody, pos1=None, pos2=None):
864
+ if pos1 != None: self.update_reframe(self.reframe1, pos1)
865
+ if pos2 != None: self.update_reframe(self.reframe2, pos2)
866
+ entity = self.model.GetEntity(entity_name)
867
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
868
+ entity = self.model.CreateJointPerpendicular(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
869
+ return IJointPerpendicular(entity)
870
+
871
+ def UseJointPerpendicular(self, entity_name, Bbody=None, Abody=None, pos1=None, pos2=None):
872
+ entity = self.model.GetEntity(entity_name)
873
+ if entity is not None and Bbody is not None and Abody is not None:
874
+ entity = self.CreateJointPerpendicular(entity_name, Bbody, Abody, pos1=pos1, pos2=pos2)
875
+ if entity is None:
876
+ raise ValueError(f"Entity not found: {entity_name}")
877
+ return IJointPerpendicular(entity)
878
+
879
+ def CreateJointDistance(self, entity_name, Bbody, Abody, pos1=None, pos2=None):
880
+ if pos1 != None: self.update_reframe(self.reframe1, pos1)
881
+ if pos2 != None: self.update_reframe(self.reframe2, pos2)
882
+ entity = self.model.GetEntity(entity_name)
883
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
884
+ entity = self.model.CreateJointDistance(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
885
+ return IJointDistance(entity)
886
+
887
+ def UseJointDistance(self, entity_name, Bbody=None, Abody=None, pos1=None, pos2=None):
888
+ entity = self.model.GetEntity(entity_name)
889
+ if entity is not None and Bbody is not None and Abody is not None:
890
+ entity = self.CreateJointDistance(entity_name, Bbody, Abody, pos1=pos1, pos2=pos2)
891
+ if entity is None:
892
+ raise ValueError(f"Entity not found: {entity_name}")
893
+ return IJointDistance(entity)
894
+
895
+ def CreateCmotion(self, entity_name, Bbody, Abody, pos=None):
896
+ if pos is not None: self.update_reframe(self.reframe, pos)
897
+ entity = self.model.GetEntity(entity_name)
898
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
899
+ entity = self.model.CreateJointCartesianMotion(entity_name, Bbody, Abody, self.reframe, self.reframe)
900
+ return IJointCartesianMotion(entity)
901
+
902
+ def UseCmotion(self, entity_name, Bbody=None, Abody=None, pos=None):
903
+ entity = self.model.GetEntity(entity_name)
904
+ if entity is not None and Bbody is not None and Abody is not None:
905
+ entity = self.CreateCmotion(entity_name, Bbody, Abody, pos=pos)
906
+ if entity is None:
907
+ raise ValueError(f"Entity not found: {entity_name}")
908
+ return IJointCartesianMotion(entity)
909
+
910
+ def CreateGCmotion(self, entity_name, Bbody, Abody, pos=None):
911
+ if pos is not None: self.update_reframe(self.reframe, pos)
912
+ entity = self.model.GetEntity(entity_name)
913
+ if entity is not None:
914
+ self.modelDocument.DeleteEntity(entity)
915
+ entity = self.model.CreateJointCartesianMotionGroup(entity_name, Bbody, Abody, self.reframe, self.reframe)
916
+ return entity
917
+
918
+ def UseGCmotion(self, entity_name, Bbody=None, Abody=None, pos=None):
919
+ entity = self.model.GetEntity(entity_name)
920
+ if entity is not None and Bbody is not None and Abody is not None:
921
+ entity = self.CreateGCmotion(entity_name, Bbody, Abody, pos=pos)
922
+ if entity is None:
923
+ raise ValueError(f"Entity not found: {entity_name}")
924
+ return IGroupJointCMotion(entity)
925
+
926
+ def UseGeneralPlantInput(self, entity_name):
927
+ entity = self.model.GetEntity(entity_name)
928
+ if entity is None:
929
+ entity = self.model.CreateGeneralPlantInput(entity_name)
930
+ return IControlGeneralPlantInput(entity)
931
+
932
+ def UseGeneralPlantOutput(self, entity_name, ex_name=None):
933
+ entity = self.model.GetEntity(entity_name)
934
+ ex = None
935
+ if ex_name is not None:
936
+ ex = self.model.GetEntity(ex_name)
937
+ if ex is None:
938
+ raise ValueError(f"Expression not found for GeneralPlantOutput: {ex_name}")
939
+ if entity is None:
940
+ if ex is None:
941
+ raise ValueError(f"Expression name is required to create GeneralPlantOutput: {entity_name}")
942
+ entity = self.model.CreateGeneralPlantOutput(entity_name, ex)
943
+ print("Created GeneralPlantOutput " + entity_name)
944
+ entity = IControlGeneralPlantOutput(entity)
945
+ if ex is not None:
946
+ entity.Expression = IExpression(ex)
947
+ return IControlGeneralPlantOutput(entity)
948
+
949
+ def CreateDataSpline(self, entity_name, data):
950
+ entity = self.model.GetEntity(entity_name)
951
+ if entity: self.modelDocument.DeleteEntity(entity)
952
+ entity = self.model.CreateSplineWithValue(entity_name, data)
953
+ return ISpline(entity)
954
+
955
+ def ModifyDataSpline(self, entity_name, data):
956
+ entity = self.model.GetEntity(entity_name)
957
+ if entity is None:
958
+ print(entity_name + " spline is not exist!")
959
+ return None
960
+ entity = ISpline(entity)
961
+ entity.Value = data
962
+ return ISpline(entity)
963
+
964
+ def CreateForceScrew(self, entity_name, Bbody, Abody, pos=None):
965
+ if pos is not None: self.update_reframe(self.reframe, pos)
966
+ entity = self.model.GetEntity(entity_name)
967
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
968
+ entity = self.model.CreateForceScrew(entity_name, Bbody, Abody, self.reframe, self.reframe)
969
+ return IForceScrew(entity)
970
+
971
+ def CreateForceTranslational(self, entity_name, Bbody, Abody, pos=None):
972
+ if pos is not None: self.update_reframe(self.reframe, pos)
973
+ entity = self.model.GetEntity(entity_name)
974
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
975
+ entity = self.model.CreateForceTranslationalEx(entity_name, Bbody, Abody, self.reframe, self.reframe)
976
+ return IForceTranslational(entity)
977
+
978
+ def UseForceTranslational(self, entity_name, Bbody=None, Abody=None, pos=None):
979
+ if pos is not None: self.update_reframe(self.reframe, pos)
980
+ entity = self.model.GetEntity(entity_name)
981
+ if entity is None:
982
+ entity = self.model.CreateForceTranslationalEx(entity_name, Bbody, Abody, self.reframe, self.reframe)
983
+ return IForceTranslational(entity)
984
+
985
+ def CreateForceAxial(self, entity_name, Bbody, Abody, pos=None):
986
+ if pos is not None: self.update_reframe(self.reframe, pos)
987
+ entity = self.model.GetEntity(entity_name)
988
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
989
+ entity = self.model.CreateForceAxialEx(entity_name, Bbody, Abody, self.reframe, self.reframe)
990
+ return IForceAxial(entity)
991
+
992
+ def CreateForceRotationalAxial(self, entity_name, Bbody, Abody, pos=None):
993
+ if pos is not None: self.update_reframe(self.reframe, pos)
994
+ entity = self.model.GetEntity(entity_name)
995
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
996
+ entity = self.model.CreateForceRotationalAxialWithBody(entity_name, Bbody, Abody, self.reframe)
997
+ return IForceAxialRotational(entity)
998
+
999
+ def CreateForceSpring(self, entity_name, Bbody, Abody, bpos=(0, 0, 0), apos=(100, 0, 0)):
1000
+ entity = self.model.GetEntity(entity_name)
1001
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
1002
+ self.update_reframe(self.reframe1, bpos)
1003
+ self.update_reframe(self.reframe2, apos)
1004
+ entity = self.model.CreateForceSpringEx(entity_name, Bbody, Abody, self.reframe1, self.reframe2)
1005
+ return IForceSpring(entity)
1006
+
1007
+ def CreateForceBushing(self, entity_name, Bbody, Abody, pos=None):
1008
+ if pos is not None: self.update_reframe(self.reframe, pos)
1009
+ entity = self.model.GetEntity(entity_name)
1010
+ if entity is not None: self.modelDocument.DeleteEntity(entity)
1011
+ entity = self.model.CreateForceBushingEx(entity_name, Bbody, Abody, self.reframe)
1012
+ return IForceBushing(entity)
1013
+
1014
+ def ModifyBushingParameter(self, entity_name, param_tra=np.zeros(6), param_rot=np.zeros(6), static=False):
1015
+ entity = self.model.GetEntity(entity_name)
1016
+ if entity is None:
1017
+ raise ValueError(f"Bushing not found: {entity_name}")
1018
+ else:
1019
+ entity = IForceBushing(entity)
1020
+ entity.TranslationalStiffnessX.Coefficient.Value = param_tra[0]
1021
+ entity.TranslationalStiffnessY.Coefficient.Value = param_tra[1]
1022
+ entity.TranslationalStiffnessZ.Coefficient.Value = param_tra[2]
1023
+ entity.TranslationalDampingX.Coefficient.Value = param_tra[3]
1024
+ entity.TranslationalDampingY.Coefficient.Value = param_tra[4]
1025
+ entity.TranslationalDampingZ.Coefficient.Value = param_tra[5]
1026
+ entity.RotationalStiffnessX.Coefficient.Value = param_rot[0]
1027
+ entity.RotationalStiffnessY.Coefficient.Value = param_rot[1]
1028
+ entity.RotationalStiffnessZ.Coefficient.Value = param_rot[2]
1029
+ entity.RotationalDampingX.Coefficient.Value = param_rot[3]
1030
+ entity.RotationalDampingY.Coefficient.Value = param_rot[4]
1031
+ entity.RotationalDampingZ.Coefficient.Value = param_rot[5]
1032
+ entity.UseStaticBushing = static
1033
+
1034
+ def CreatePlantInput(self, entity_name):
1035
+ entity = self.model.GetEntity(entity_name)
1036
+ if entity is None:
1037
+ entity = self.model.CreateGeneralPlantInput(entity_name)
1038
+ return IControlGeneralPlantInput(entity)
1039
+
1040
+ def CreatePlantOutput(self, entity_name, expression):
1041
+ entity = self.model.GetEntity(entity_name)
1042
+ if entity is None:
1043
+ entity = self.model.CreateGeneralPlantOutput(entity_name, expression)
1044
+ return IControlGeneralPlantOutput(entity)
1045
+
1046
+ def CreateExpression(self, entity_name, value_text="0"):
1047
+ entity = self.model.GetEntity(entity_name)
1048
+ if entity: self.modelDocument.DeleteEntity(entity)
1049
+ entity = self.model.CreateExpression(entity_name, value_text)
1050
+ return IExpression(entity)
1051
+
1052
+ def CreateExpressionArguments(self, entity_name, value_text, arguments):
1053
+ argument_names = []
1054
+ for argument in arguments:
1055
+ argument_names.append(argument.FullName.replace("@" + self.model.FullName, ""))
1056
+ entity = self.model.GetEntity(entity_name)
1057
+ if entity:
1058
+ self.modelDocument.DeleteEntity(entity)
1059
+ entity = self.model.CreateExpression(entity_name, "0")
1060
+ entity = IExpression(entity)
1061
+ entity.Arguments = argument_names
1062
+ entity.Text = value_text
1063
+ return entity
1064
+
1065
+ def ModifyExpressionArguments(self, entity_name, arguments, value_text=None):
1066
+ argument_names = []
1067
+ for argument in arguments:
1068
+ argument_names.append(argument.FullName.replace("@" + self.model.FullName, ""))
1069
+ entity = self.model.GetEntity(entity_name)
1070
+ if entity is None:
1071
+ raise ValueError(f"Expression not found: {entity_name}")
1072
+ entity = IExpression(entity)
1073
+ entity.Arguments = argument_names
1074
+ if value_text is not None:
1075
+ entity.Text = value_text
1076
+ return entity
1077
+
1078
+ def CreateGcon(self, entity_name, expression ):
1079
+ entity = self.model.GetEntity(entity_name)
1080
+ if entity: self.modelDocument.DeleteEntity(entity)
1081
+ entity = self.model.CreateGeneralConstraint(entity_name, expression)
1082
+ return IGeneralConstraint(entity)
1083
+
1084
+ def CreateDifferentialEqn(self, entity_name, expression):
1085
+ entity = self.model.GetEntity(entity_name)
1086
+ if entity: self.modelDocument.DeleteEntity(entity)
1087
+ entity = self.model.CreateDifferentialEquation(entity_name, DifferentialEquationFunctionType.Explicit, expression)
1088
+ return IDifferentialEquation(entity)
1089
+
1090
+ def UseExpression(self, entity_name, expression_text=None):
1091
+ entity = self.model.GetEntity(entity_name)
1092
+ if entity is None:
1093
+ entity = self.model.CreateExpression(entity_name, "0")
1094
+ if expression_text != None:
1095
+ IExpression(entity).Text = expression_text
1096
+ return IExpression(entity)
1097
+
1098
+ def CreateParametricValue(self, entity_name, value):
1099
+ entity = self.model.GetEntity(entity_name)
1100
+ if entity:
1101
+ self.modelDocument.DeleteEntity(entity)
1102
+ entity = self.model.CreateParametricValue(entity_name, value)
1103
+ return IParametricValue(entity)
1104
+
1105
+ def UseParametricValue(self, entity_name, value=None):
1106
+ entity = self.model.GetEntity(entity_name)
1107
+ if entity is None:
1108
+ entity = self.model.CreateParametricValue(entity_name, 0)
1109
+ if value is not None:
1110
+ IParametricValue(entity).Value = value
1111
+ IParametricValue(entity).Value = value
1112
+ return IParametricValue(entity)
1113
+
1114
+ def CreateParametricPoint(self, entity_name, point=(0.0, 0.0, 0.0), ref_mkr=None):
1115
+ entity = self.model.GetEntity(entity_name)
1116
+ if entity:
1117
+ self.modelDocument.DeleteEntity(entity)
1118
+ entity = self.model.CreateParametricPoint(entity_name, point, ref_mkr)
1119
+ return IParametricPoint(entity)
1120
+
1121
+ def UseParametricPoint(self, pp_name, point=None, ref_mkr=None):
1122
+ pp = self.model.GetEntity(pp_name)
1123
+ if pp is None:
1124
+ if point is None: point=(0.0, 0.0, 0.0)
1125
+ pp = self.model.CreateParametricPoint(pp_name, point, ref_mkr)
1126
+ print(pp_name + " is created!")
1127
+ pp = IParametricPoint(pp)
1128
+ if point is not None:
1129
+ pp.PointX.Value = point[0]
1130
+ pp.PointY.Value = point[1]
1131
+ pp.PointZ.Value = point[2]
1132
+ return IParametricPoint(pp)
1133
+
1134
+ def CreateParametricValueConnector(self, entity_name, pv_name):
1135
+ entity = self.model.GetEntity(entity_name)
1136
+ if entity:
1137
+ self.modelDocument.DeleteEntity(entity)
1138
+ entity = IParametricValueConnector(self.model.CreateParametricValueConnector(entity_name))
1139
+ entity.Value.ParametricValue = self.UseParametricValue(pv_name)
1140
+ for sub in self.Subsystems:
1141
+ sub = ISubSystem(sub)
1142
+ for pv in sub.ParametricValueCollection:
1143
+ pv = IParametricValue(pv)
1144
+ if pv.Name == pv_name:
1145
+ entity.Add(pv)
1146
+ break
1147
+ return IParametricValueConnector(entity)
1148
+
1149
+ def UsePlaneSymmetriyPPS(self, ref_pp_prefix, copy_pp_prefix, sym_axis):
1150
+ for pp in self.model.ParametricPointCollection:
1151
+ pp = IParametricPoint(pp)
1152
+ if ref_pp_prefix in pp.Name:
1153
+ pp_cnt_name = pp.Name.replace(ref_pp_prefix, copy_pp_prefix)
1154
+ self.UsePlaneSymmetriyPP(pp.Name, pp_cnt_name, sym_axis)
1155
+
1156
+ def UsePlaneSymmetriyPP(self, pp_Name, pp_sym_name, sym_axis):
1157
+ pp = self.model.GetEntity(pp_Name)
1158
+ if pp is None:
1159
+ raise ValueError(f"Parametric point not found: {pp_Name}")
1160
+ pp_sym = self.model.GetEntity(pp_sym_name)
1161
+ if pp_sym is None:
1162
+ pp_sym = self.model.CreateParametricPoint(pp_sym_name, [0, 0, 0], None)
1163
+ sym_axis = str(sym_axis)
1164
+ pp_value_text = ''
1165
+ if sym_axis.upper() == 'Y':
1166
+ pp_value_text = pp.Name + ".X, -" + pp.Name + ".Y, " + pp.Name + ".Z";
1167
+ elif sym_axis.upper() == 'Z':
1168
+ pp_value_text = pp.Name + ".X, " + pp.Name + ".Y, -" + pp.Name + ".Z";
1169
+ else:
1170
+ pp_value_text = "-" + pp.Name + ".X, " + pp.Name + ".Y, " + pp.Name + ".Z"
1171
+ pp_sym = IParametricPoint(pp_sym)
1172
+ pp_sym.Text = pp_value_text
1173
+ return pp_sym
1174
+
1175
+ def SetOutput(self, OutputFileName):
1176
+ self.modelDocument.UseOutputFileName = True
1177
+ self.application.Settings.CreateOutputFolder = False
1178
+ self.modelDocument.OutputFileName = OutputFileName
1179
+
1180
+ def SetOutputMsgInform(self):
1181
+ self.modelDocument.MessageFileSettings.SolverInformation = True
1182
+ self.modelDocument.MessageFileSettings.AnalysisInformation = True
1183
+ self.modelDocument.MessageFileSettings.IntegratorInformation = True
1184
+ self.modelDocument.MessageFileSettings.ConstraintInformation = False
1185
+ self.modelDocument.MessageFileSettings.AnalysisProcess = True
1186
+
1187
+ def RunDynamicAnalysis(self, stime=None, steps=None, OutputFileName=None):
1188
+ if OutputFileName:
1189
+ self.modelDocument.UseOutputFileName = True
1190
+ self.application.Settings.CreateOutputFolder = False
1191
+ self.modelDocument.OutputFileName = OutputFileName
1192
+ if stime:
1193
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationTime.Value = stime
1194
+ if steps:
1195
+ self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationStep.Value = steps
1196
+ self.modelDocument.Analysis(AnalysisMode.Dynamic)
1197
+ return self.modelDocument.OutputFileName
1198
+
1199
+ def ImportSubsystem(self, filename, subsystem_name=None):
1200
+ bf_sub_names = [SubSystem.Name for SubSystem in self.modelDocument.Model.SubSystemCollection]
1201
+ try:
1202
+ self.modelDocument.FileImport(filename)
1203
+ except:
1204
+ exit("Invalid subsystem file name: " + filename)
1205
+ af_sub_names = [SubSystem.Name for SubSystem in self.modelDocument.Model.SubSystemCollection]
1206
+ imported_subsystem_name = [name for name in af_sub_names if name not in bf_sub_names][0]
1207
+ subsystem = ISubSystem(self.modelDocument.Model.GetEntity(imported_subsystem_name))
1208
+ if subsystem_name is not None:
1209
+ try:
1210
+ subsystem.Name = subsystem_name
1211
+ except:
1212
+ exit("Subsystem name is already exist : " + subsystem_name)
1213
+ print("Subsystem imported: " + subsystem.Name)
1214
+ return subsystem
1215
+
1216
+ def RunFRAAnalysis(self, fs=0.1, fe=100, step=100, log=True, frame=30, amp=1, nmode=10, dmp=True, statemtx=True):
1217
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.StartFrequency.Value = fs
1218
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.EndFrequency.Value = fe
1219
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.Step.Value = step
1220
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.LogarithmicStep = log
1221
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.AnimationFrame.Value = frame
1222
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.AmplitudeFactor.Value = amp
1223
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.MaxNumberofMode.Value = nmode
1224
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.IncludeSystemDamping = dmp
1225
+ self.modelDocument.ModelProperty.FrequencyResponseAnalysisProperty.IncludeStateMatrix = statemtx
1226
+ self.modelDocument.Analysis(AnalysisMode.FRA)
1227
+
1228
+ def RunStaticAnalysis(self, time=0, steps=1, OutputFileName=None):
1229
+ if OutputFileName:
1230
+ self.modelDocument.UseOutputFileName = True
1231
+ self.application.Settings.CreateOutputFolder = False
1232
+ self.modelDocument.OutputFileName = OutputFileName
1233
+ if time: self.modelDocument.ModelProperty.StaticAnalysisProperty.Time.Value = time
1234
+ if steps: self.modelDocument.ModelProperty.StaticAnalysisProperty.Step.Value = steps
1235
+ self.modelDocument.Analysis(AnalysisMode.Static)
1236
+
1237
+ def RecordAnimation(self, filename, fps=30):
1238
+ self.modelDocument.ModelSetting.ShowIconAll = False
1239
+ self.modelDocument.ModelSetting.ShowMarkerCenter = False
1240
+ self.modelDocument.ModelSetting.ShowMarkerGeneral = False
1241
+ self.modelDocument.ModelSetting.AnimationControl.FrameStep = 3
1242
+ ani = IAnimation(self.modelDocument.Animation)
1243
+ # Codec Names: Intel Indeo(R) 비디오 YUV 코덱, Microsoft Video 1 Compressor, Google VP8 VFW Video Codec, Uncompressed
1244
+ # ani.SaveOption.Codec = "Google VP8 VFW Video Codec"
1245
+ ani.SaveOption.FramePerSecond = fps
1246
+ # ani.SaveOption.ResolutionX = 1280
1247
+ # ani.SaveOption.ResolutionY = 720
1248
+ ani.SaveOption.ShowTime = True
1249
+ ani.Save2(filename, True)
1250
+ return filename
1251
+
1252
+ def PlayAnimation(self):
1253
+ Animation = IAnimation(self.modelDocument.Animation)
1254
+ Animation.Play()
1255
+ while Animation.CurrentFrame != Animation.NumberOfFrame: pass
1256
+ Animation.Stop()
1257
+
1258
+ def SaveModelDocument(self, new_name=None):
1259
+ if new_name:
1260
+ self.modelDocument.FileSave(new_name, True)
1261
+ else:
1262
+ self.modelDocument.FileSave(self.modelDocument.GetPath(PathType.WorkingDocument), True)
1263
+
1264
+ def CloseModelDocument(self, modeldoc_name=None):
1265
+ if modeldoc_name is None:
1266
+ self.application.CloseModelDocument(self.modelDocument)
1267
+ return
1268
+ modeldoc = self.application.GetModelDocument(modeldoc_name)
1269
+ if modeldoc:
1270
+ self.application.CloseModelDocument(modeldoc)
1271
+ else:
1272
+ return
1273
+
1274
+ def ExportWallFilePW(self, file_path=""):
1275
+ # clear obj files
1276
+ model_path = Path(self.modelDocument.GetPath(PathType.WorkingFolder))
1277
+ wall_folder_path = model_path.joinpath('WallGeometries')
1278
+ if os.path.isdir(wall_folder_path):
1279
+ import shutil
1280
+ shutil.rmtree(wall_folder_path)
1281
+ import recurdyn.ExternalSPI as ExtSPI
1282
+ ExtSPIToolkit = ExtSPI.IExternalSPIToolkit(self.model.ExternalSPIToolkit)
1283
+ ExtSPIToolkit.Program = 'Particleworks'
1284
+ ExtSPIToolkit.ExportWallFile(file_path)
1285
+
1286
+ def CreateWallBody(self, body):
1287
+ try:
1288
+ body = IBody(body)
1289
+
1290
+ wall_name = "Wall_" + body.Name
1291
+ wall = self.model.GetEntity(wall_name)
1292
+ if wall is None:
1293
+ wall = self.ExtSPI.CreateWall(wall_name, body)
1294
+ return wall
1295
+ except:
1296
+ print("invalid body for wall")
1297
+ return None
1298
+
1299
+ def CreateWallGeometry(self, geo):
1300
+ try:
1301
+ geo = IGeometry(geo)
1302
+ import recurdyn.ExternalSPI as ExtSPI
1303
+ ExtSPIToolkit = ExtSPI.IExternalSPIToolkit(self.model.ExternalSPIToolkit)
1304
+ ExtSPIToolkit.Program = 'Particleworks'
1305
+ wall_name = "Wall_" + geo.OwnerBody.Name + "_" + geo.Name
1306
+ wall = self.model.GetEntity(wall_name)
1307
+ if wall is None:
1308
+ wall = ExtSPIToolkit.CreateWall(wall_name, geo)
1309
+ return wall
1310
+ except:
1311
+ print("invalid body for wall")
1312
+ return None
1313
+
1314
+ def SPIAnimationColor(self, body_name):
1315
+ pass
1316
+
1317
+ def CreateScrewForce(self, entity_name, Bbody, Abody, pos=None):
1318
+ if pos is not None: self.update_reframe(self.reframe, pos)
1319
+ entity = self.model.GetEntity(entity_name)
1320
+ if entity: self.modelDocument.DeleteEntity(entity)
1321
+ entity = self.model.CreateForceScrew(entity_name, Bbody, Abody, self.reframe, self.reframe)
1322
+ return IForceScrew(entity)
1323
+
1324
+ # def DeleteAll(self):
1325
+ # # self.modelDocument.SelectAll()
1326
+ # for entity in self.model.ParametricValueCollection:
1327
+ # self.modelDocument.Select(SelectType.Add, entity)
1328
+ # for entity in self.model.ParametricValueConnectorCollection:
1329
+ # self.modelDocument.Select(SelectType.Add, entity)
1330
+ # for entity in self.model.ExpressionCollection:
1331
+ # self.modelDocument.Select(SelectType.Add, entity)
1332
+ # for entity in self.model.GeneralConstraintCollection:
1333
+ # self.modelDocument.Select(SelectType.Add, entity)
1334
+ # for entity in self.model.GeneralPlantInputCollection:
1335
+ # self.modelDocument.Select(SelectType.Add, entity)
1336
+ # for entity in self.model.GeneralPlantOutputCollection:
1337
+ # self.modelDocument.Select(SelectType.Add, entity)
1338
+ # self.modelDocument.Delete()
1339
+
1340
+ def DeleteAllBodies(self):
1341
+ self.modelDocument.DeselectAll()
1342
+ for entity in self.model.BodyCollection:
1343
+ self.modelDocument.Select(SelectType.Add, entity)
1344
+ self.modelDocument.Delete()
1345
+
1346
+ def DeleteAll(self):
1347
+ self.modelDocument.SelectAll()
1348
+ self.modelDocument.Delete()
1349
+
1350
+ def DeleteAllParametricPoint(self):
1351
+ self.modelDocument.DeselectAll()
1352
+ for entity in self.model.ParametricPointCollection:
1353
+ self.modelDocument.Select(SelectType.Add, entity)
1354
+ self.modelDocument.Delete()
1355
+
1356
+ def DeleteAllParametricPointConnector(self):
1357
+ self.modelDocument.DeselectAll()
1358
+ for entity in self.model.ParametricPointConnectorCollection:
1359
+ self.modelDocument.Select(SelectType.Add, entity)
1360
+ self.modelDocument.Delete()
1361
+
1362
+ def DeleteAllParametricValue(self):
1363
+ self.modelDocument.DeselectAll()
1364
+ for entity in self.model.ParametricValueCollection:
1365
+ self.modelDocument.Select(SelectType.Add, entity)
1366
+ self.modelDocument.Delete()
1367
+
1368
+ def DeleteAllParametricValueConnector(self):
1369
+ self.modelDocument.DeselectAll()
1370
+ for entity in self.model.ParametricValueConnectorCollection:
1371
+ self.modelDocument.Select(SelectType.Add, entity)
1372
+ self.modelDocument.Delete()
1373
+
1374
+ def SetRelativePathRFIfile(self):
1375
+ rflexToolkit = IRFlexToolkit(self.model.RFlexToolkit)
1376
+ for rflexBody in rflexToolkit.RFlexBodyCollection:
1377
+ rflexBody = IRFlexBody(rflexBody)
1378
+ rfi_path = Path(rflexBody.RFIFileName)
1379
+ model_path = Path(self.modelDocument.GetPath(PathType.WorkingFolder))
1380
+ print(rfi_path)
1381
+ print(model_path)
1382
+ local_path = rfi_path.relative_to(model_path)
1383
+ print(local_path)
1384
+ rflexBody.RFIFileName = str(local_path)
1385
+
1386
+ def SetFolderPathRFIFile(self, Folder="./Rflex"):
1387
+ for rflexBody in IRFlexToolkit(self.model.RFlexToolkit).RFlexBodyCollection:
1388
+ rflexBody = IRFlexBody(rflexBody)
1389
+ rfi_file = os.path.basename(Path(rflexBody.RFIFileName))
1390
+ print(rfi_file)
1391
+ model_path = Path(self.modelDocument.GetPath(PathType.WorkingFolder))
1392
+ rflexBody = IRFlexBody(rflexBody)
1393
+ New_path = Path(Folder).joinpath(rfi_file)
1394
+ print(New_path)
1395
+ rflexBody.RFIFileName = str(New_path)
1396
+ for sub in self.Subsystems:
1397
+ sub = ISubSystem(sub)
1398
+ rflexToolkit = IRFlexToolkit(sub.RFlexToolkit)
1399
+ for rflexBody in rflexToolkit.RFlexBodyCollection:
1400
+ rflexBody = IRFlexBody(rflexBody)
1401
+ rfi_file = os.path.basename(Path(rflexBody.RFIFileName))
1402
+ print(rfi_file)
1403
+ model_path = Path(self.modelDocument.GetPath(PathType.WorkingFolder))
1404
+ rflexBody = IRFlexBody(rflexBody)
1405
+ New_path = Path(Folder).joinpath(rfi_file)
1406
+ print(New_path)
1407
+ rflexBody.RFIFileName = str(New_path)
1408
+
1409
+ def ReplaceRflextoRlexwithRFI(self, rflex_body_name, rfi_path):
1410
+ gManager = Flexible.IGManager(self.application.ActiveModelDocument.Model.GManager)
1411
+ # gManager = Flexible.IGManager(self.model.GManager)
1412
+ body = self.UseBody(rflex_body_name)
1413
+ gManager.SourceBody = body
1414
+ gManager.TargetBodyType = Flexible.BodyType.BodyType_RFLEX
1415
+ gManagerRFlex = Flexible.IGManagerRFlex(gManager.RFlex)
1416
+ gManagerRFlexToRFlex = Flexible.IGManagerRFlexToRFlex(gManagerRFlex.RFlex)
1417
+ gManagerRFlexToRFlex.ConvertType = Flexible.ConvertRFlexToRFlexType.RFlexToRFlex_Swap_RFI
1418
+ gManagerRFlexToRFlex.FileName = rfi_path
1419
+ gManagerRFlexToRFlex.ReferenceFrame = body.RefFrame
1420
+ gManagerRFlexToRFlex.SwapOption.UseUserDefinedRigidBodyFrequency = 0.01
1421
+ assistModelingOption = Flexible.IGManagerAssistModelingOption(gManagerRFlexToRFlex.AssistModelingOption)
1422
+ assistModelingOption.UseName = True
1423
+ assistModelingOption.TargetBodyName = body.Name
1424
+ assistModelingOption.UseInitialVelocity = True
1425
+ assistModelingOption.UseJoint = True
1426
+ assistModelingOption.UseForce = True
1427
+ assistModelingOption.UseGeoContact = True
1428
+ gManager.Execute()
1429
+ body = self.UseBody(rflex_body_name)
1430
+ body.Redraw()
1431
+
1432
+ def DeleteNamedBodies(self, name):
1433
+ self.modelDocument.DeselectAll()
1434
+ for body in self.model.BodyCollection:
1435
+ if name in IBody(body).Name:
1436
+ self.modelDocument.Select(SelectType.Add, body)
1437
+ self.modelDocument.Delete()
1438
+ self.model.DeleteUnusedMarkers()
1439
+
1440
+ def RunEigenValueAnalysis(self, nmode=30, frame=30, amplitude=1, stime=0.0, etime=1.0, cutoff=0.1, static=True):
1441
+ EigenValueProperty = IEigenValueProperty(self.modelDocument.ModelProperty.EigenValueAnalysisProperty)
1442
+ EigenValueProperty.StartTime.Value = stime
1443
+ EigenValueProperty.NaturalFrequencyType = NaturalFrequencyType.NaturalFrequencyType_Damped
1444
+ EigenValueProperty.EndTime.Value = etime
1445
+ EigenValueProperty.FramePerCycle.Value = frame
1446
+ EigenValueProperty.UseCutoffLowFrequency = True
1447
+ EigenValueProperty.CutoffLowFrequency.Value = cutoff
1448
+ # EigenValueProperty.AmplitudeFactor.Value = amplitude
1449
+ EigenValueProperty.MaxModeNumber.Value = nmode
1450
+ EigenValueProperty.IncludeStaticAnalysis = static
1451
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforOutput = True
1452
+ self.modelDocument.Analysis(AnalysisMode.EigenValue)
1453
+ return self.modelDocument.OutputFileName + ".out"
1454
+
1455
+ def EigenValueAnalysisProperty(self, stime, etime, cycle, amplitude, cutoff, mode_number, include_static):
1456
+ EigenValueProperty = IEigenValueProperty(self.modelDocument.ModelProperty.EigenValueAnalysisProperty)
1457
+ EigenValueProperty.StartTime.Value = stime
1458
+ EigenValueProperty.NaturalFrequencyType = NaturalFrequencyType.NaturalFrequencyType_Damped
1459
+ EigenValueProperty.EndTime.Value = etime
1460
+ EigenValueProperty.FramePerCycle.Value = cycle
1461
+ EigenValueProperty.UseCutoffLowFrequency = True
1462
+ EigenValueProperty.CutoffLowFrequency.Value = cutoff
1463
+ EigenValueProperty.AmplitudeFactor.Value = amplitude
1464
+ EigenValueProperty.MaxModeNumber.Value = mode_number
1465
+ EigenValueProperty.IncludeStaticAnalysis = include_static
1466
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforOutput = True
1467
+
1468
+ def RFlexContour(self, frame):
1469
+ rflexToolkit = IRFlexToolkit(self.model.RFlexToolkit)
1470
+ rflexToolkit.Contour.EnableView = True
1471
+ Animation = IAnimation(self.modelDocument.Animation)
1472
+ if 0 < frame <= Animation.NumberOfFrame:
1473
+ Animation.CurrentFrame = frame
1474
+ else:
1475
+ Animation.CurrentFrame = Animation.NumberOfFrame
1476
+
1477
+ def ChangeModelUnit(self, units="MMKS"):
1478
+ unit = IUnit(self.modelDocument.Unit)
1479
+ if units.upper() == "MMKS":
1480
+ unit.UnitForce = UnitForce.Newton
1481
+ unit.UnitLength = UnitLength.Millimeter
1482
+ unit.UnitMass = UnitMass.Kilogram
1483
+ unit.UnitTime = UnitTime.Second
1484
+ if units.upper() == "MKS":
1485
+ unit.UnitForce = UnitForce.Newton
1486
+ unit.UnitLength = UnitLength.Meter
1487
+ unit.UnitMass = UnitMass.Kilogram
1488
+ unit.UnitTime = UnitTime.Second
1489
+ if units.upper() == "CMKS":
1490
+ unit.UnitForce = UnitForce.Newton
1491
+ unit.UnitLength = UnitLength.Centimeter
1492
+ unit.UnitMass = UnitMass.Kilogram
1493
+ unit.UnitTime = UnitTime.Second
1494
+ self.modelDocument.Utility.ChangeModelUnit(unit, False)
1495
+
1496
+ def CreateFolder(self, folder):
1497
+ try:
1498
+ if not os.path.exists(folder):
1499
+ os.makedirs(folder)
1500
+ except OSError:
1501
+ print('Error: Creating directory. ' + folder)
1502
+ return folder
1503
+
1504
+ def ExportRMD(self, path):
1505
+ Option1 = self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRAD
1506
+ Option2 = self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforSolverGeneratedAnimation
1507
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRAD = True
1508
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforSolverGeneratedAnimation = False
1509
+ path = self.CreateFolder(path)
1510
+ rmd_file = path + "/" + self.modelDocument.Model.Name + ".rmd"
1511
+ self.modelDocument.FileExport(rmd_file, True)
1512
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforRAD = Option1
1513
+ self.modelDocument.ModelProperty.CommonAnalysisProperty.SimulationResultFileforSolverGeneratedAnimation = Option2
1514
+ return rmd_file
1515
+
1516
+ def ExportRSS(self, path):
1517
+ path = self.CreateFolder(path)
1518
+ tend = str(self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationTime.Value)
1519
+ steps = str(int(self.modelDocument.ModelProperty.DynamicAnalysisProperty.SimulationStep.Value))
1520
+ rss_file = path + "/" + self.modelDocument.Model.Name + ".rss"
1521
+ fid = open(rss_file, "w")
1522
+ fid.write("SIM / DYN, END = " + tend + ", STEP = " + steps + "\n")
1523
+ fid.write("STOP")
1524
+ fid.close()
1525
+ return rss_file
1526
+
1527
+ def ExportBAT(self, path):
1528
+ path = self.CreateFolder(path)
1529
+ reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
1530
+ r"SOFTWARE\FunctionBay, Inc.\RecurDyn " + self.rd_ver + r"\Path", 0, winreg.KEY_READ)
1531
+ value, d_type = winreg.QueryValueEx(reg_key, "ROOT")
1532
+ rdsolver_path = value + r"\Bin\Solver\RDSolverRun.exe"
1533
+ bat_file = path + "/" + self.modelDocument.Model.Name + ".bat"
1534
+ fid = open(bat_file, "w")
1535
+ fid.write(
1536
+ "call \"" + rdsolver_path + "\" " + self.modelDocument.Model.Name + " " + self.modelDocument.Model.Name)
1537
+ fid.close()
1538
+ return bat_file
1539
+
1540
+ def ExportSolverModel(self, path):
1541
+ self.ExportRMD(path)
1542
+ self.ExportRSS(path)
1543
+ self.ExportBAT(path)
1544
+
1545
+ def AssemblyTrackHM(self, subSystem, asm_name, wheel_names, link_name, nlink):
1546
+ # Into Subsystem
1547
+ self.modelDocument.ChangeDataStorage(subSystem)
1548
+ trackHMSub = ITrackHMSubSystem(subSystem.TrackHMSubSystem)
1549
+ # Get LinkBody
1550
+ link = ITrackHMLinkClone(subSystem.GetEntity(link_name))
1551
+ # Gather Wheel Bodies
1552
+ wheel_bodies = []
1553
+ for name in wheel_names:
1554
+ body = subSystem.GetEntity(name)
1555
+ wheel_bodies.append(body)
1556
+ # In/Out List
1557
+ InOut = [TrackHMInOutType.TrackHMInOutType_Out for i in range(len(wheel_bodies))]
1558
+ # Assembly Track
1559
+ asm = subSystem.GetEntity(asm_name)
1560
+ if asm: self.modelDocument.DeleteEntity(asm)
1561
+ asm = trackHMSub.CreateTrackAssemblyWithAutomaticSprocketAlignment(asm_name, link, wheel_bodies, InOut, nlink)
1562
+ # Geometry Setup
1563
+ for lnk in asm.TrackHMBodyLinkCollection:
1564
+ lnk.Graphic.Color = Color.MediumSlateBlue
1565
+ lnk.Graphic.EachRenderMode = EachRenderMode.Each_Shade_With_Wire
1566
+ return link, wheel_bodies, asm
1567
+
1568
+ def CreatecontactTracktoSurface(self, subSystem, cnt_name, track_asm, road_surface):
1569
+ # Into Subsystem
1570
+ self.modelDocument.ChangeDataStorage(subSystem)
1571
+ trackHMSub = ITrackHMSubSystem(subSystem.TrackHMSubSystem)
1572
+ contactTrackToSurface = subSystem.GetEntity(cnt_name)
1573
+ if contactTrackToSurface: self.modelDocument.DeleteEntity(contactTrackToSurface)
1574
+ contactTrackToSurface = trackHMSub.CreateContactTrackToSurface(cnt_name, track_asm, road_surface)
1575
+ return contactTrackToSurface
1576
+
1577
+ def CopyEntity(self, name, new_name):
1578
+ entity = self.model.GetEntity(name)
1579
+ if entity is None:
1580
+ raise ValueError(f"Entity not found: {name}")
1581
+ if self.model.GetEntity(new_name):
1582
+ raise ValueError(f"Entity already exists, cannot copy: {new_name}")
1583
+ self.modelDocument.Select(SelectType.Only, entity)
1584
+ self.modelDocument.Copy()
1585
+ self.modelDocument.DeselectAll() # Error shown without deselect
1586
+ self.modelDocument.Paste(PasteType.WithPrefix, "TEMP_COPIED_ENTITY_")
1587
+ copied_entity = self.model.GetEntity("TEMP_COPIED_ENTITY_" + name)
1588
+ copied_entity.Name = new_name
1589
+ self.modelDocument.UpdateDatabaseWindow()
1590
+ return copied_entity
1591
+ #
1592
+ # def CopyBody(self, name, new_name):
1593
+ # entity = IBody(self.model.GetEntity(name))
1594
+ # if entity is None:
1595
+ # sys.exit("Entity " + name + " is not exist")
1596
+ # if self.model.GetEntity(new_name):
1597
+ # sys.exit("Entity " + new_name + " is already exist, It cannot be copied")
1598
+ # self.modelDocument.Select(SelectType.Only, entity)
1599
+ # self.modelDocument.Copy()
1600
+ # self.modelDocument.Paste(PasteType.WithPrefix, "TEMP_COPIED_ENTITY_")
1601
+ # copied_entity = IBody(self.model.GetEntity("TEMP_COPIED_ENTITY_" + name))
1602
+ # copied_entity.Name = new_name
1603
+ # print(copied_entity.Name)
1604
+ # time.sleep(2)
1605
+ # # self.modelDocument.UpdateDatabaseWindow()
1606
+ # return copied_entity
1607
+
1608
+ def DeleteEntity(self, Entity):
1609
+ try:
1610
+ self.modelDocument.DeleteEntity(Entity)
1611
+ except:
1612
+ pass
1613
+
1614
+ def SelectEntities(self, names, database):
1615
+ self.modelDocument.DeselectAll()
1616
+ for name in names:
1617
+ obj = database.GetEntity(name)
1618
+ if obj:
1619
+ self.modelDocument.Select(SelectType.Add, obj)
1620
+
1621
+ def SetBackup(self, open_backup=True, save_before=True, svae_after=False):
1622
+ self.modelDocument.ModelSetting.ModelSettingGeneral.CreateBackupFile = open_backup
1623
+ self.application.Settings.SaveBeforSimulation = save_before
1624
+ self.application.Settings.SaveAfterSimulation = svae_after
1625
+
1626
+ def StartMeshmode(self, body):
1627
+ self.MeshMode = IMeshMode(IFFlexToolkit(self.model.FFlexToolkit).MeshMode)
1628
+ self.MeshMode.Start(body)
1629
+
1630
+ def BeamAutoMesh(self, geo_name):
1631
+ geo = self.MeshMode.FFlexBody.GetEntity(geo_name)
1632
+ return IMesherBeamMeshOption(self.MeshMode.BeamMeshOption(geo))
1633
+
1634
+ def SetColorFlex(self, Fbody, name, ColorCode=Color.SlateBlue, show=True):
1635
+ def chg_color(obj, show=True, ColorCode=Color.SlateBlue):
1636
+ obj.Show = show
1637
+ obj.Color = Color.rgb_to_bgr(ColorCode)
1638
+ print("SetColor: " + obj.Name + "(" + str(ColorCode.name) + ")")
1639
+ self.model.Ground.Redraw()
1640
+
1641
+ for obj in Fbody.DisplaySetting.DisplaySettingPropertyComponentCollection:
1642
+ if obj.Name == name:
1643
+ chg_color(obj, show, ColorCode);
1644
+ return
1645
+ for obj in Fbody.DisplaySetting.DisplaySettingElementComponentCollection:
1646
+ if obj.Name == name:
1647
+ chg_color(obj, show, ColorCode);
1648
+ return
1649
+ for obj in Fbody.DisplaySetting.DisplaySettingElementSetCollection:
1650
+ if obj.Name == name:
1651
+ chg_color(obj, show, ColorCode);
1652
+ return
1653
+ for obj in Fbody.DisplaySetting.DisplaySettingNodeSetCollection:
1654
+ if obj.Name == name:
1655
+ chg_color(obj, show, ColorCode);
1656
+ return
1657
+ for obj in Fbody.DisplaySetting.DisplaySettingPatchSetCollection:
1658
+ if obj.Name == name:
1659
+ chg_color(obj, show, ColorCode);
1660
+ return
1661
+ for obj in Fbody.DisplaySetting.DisplaySettingLineSetCollection:
1662
+ if obj.Name == name:
1663
+ chg_color(obj, show, ColorCode);
1664
+ return
1665
+
1666
+ def GetPlotData(self, EntityName="time", ContentsName=""):
1667
+ if EntityName.upper().strip() == "TIME":
1668
+ return self.modelDocument.GetPlotDataTime()
1669
+ else:
1670
+ return self.modelDocument.GetPlotData(self.model.GetEntity(EntityName), ContentsName)
1671
+
1672
+ def Exit(self):
1673
+ self.application.Exit()
1674
+ time.sleep(1)