def make_frame_from_name(partname, root_transformation): shape_marker = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape_marker, partname)): frame_marker = chrono.ChFrameD() mydoc.FromCascadeToChrono(shape_marker.Location(), frame_marker) frame_marker.ConcatenatePreTransformation(root_transformation) return frame_marker else: raise ValueError("Warning. Marker part name cannot be found in STEP file.\n")
def make_body_from_name(partname, root_transformation): shape1 = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape1, partname)): # Make a ChBody representing the TopoDS_Shape part from the CAD: mbody1 = cascade.ChBodyEasyCascade(shape1, # shape 1000, # density (center of mass & inertia automatically computed) True, # mesh for visualization? False) # mesh for collision? mysystem.Add(mbody1) # Move the body as for global displacement/rotation (also mbody1 %= root_frame; ) mbody1.ConcatenatePreTransformation(root_transformation) return mbody1 else: raise ValueError("Warning. Body part name cannot be found in STEP file.\n")
rotation2.Q_from_AngAxis(chrono.CH_C_PI, chrono.ChVectorD(0, 1, 0)) # 2: rotate 180° on vertical Y axis tot_rotation = chrono.ChQuaternionD() tot_rotation = rotation2 % rotation1 # rotate on 1 then on 2, using quaternion product root_frame = chrono.ChFrameMovingD(chrono.ChVectorD(0, 0, 0), tot_rotation) # Retrieve some sub shapes from the loaded model, using # the GetNamedShape() function, that can use path/subpath/subsubpath/part # syntax and * or ? wildcards, etc. mrigidBody1 = 0 mrigidBody2 = 0 if load_ok: shape1 = TopoDS.TopoDS_Shape() if (mydoc.GetNamedShape(shape1, "Assem1/body1")): mbody1 = mydoc.CreateBodyFromShape(shape1, 1000, False, True) # or: mbody1 = cascade.ChBodyEasyCascade(shape1, 1000, False, True) mysystem.Add(mbody1) mbody1.SetBodyFixed(True) # Move the body as for global displacement/rotation (also mbody1 %= root_frame; ) mbody1.ConcatenatePreTransformation(root_frame) mrigidBody1 = mbody1 else: print("Warning. Desired object not found in document \n")