3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Import object into user created origin reference frame (scripting)

    • Steven
      Subscriber

      Hello, I am technically doing this in Speos, but I thought this would be the best forum for the question as it seems to be mostly about SpaceClaim API rather than the Speos specific API. 

      I am trying to import an object (from a file) and have it be pulled into the frame of reference by a user created origin. However, I cannot find how to specify the frame of reference in the import command 

      When done manually it works, but when I record the actions for use in a script it seems to leave out a critical component (i.e. the selectrion of the origin as the reference frame)

      # Insert From File
      importOptions = ImportOptions.Create()
      DocumentInsert.Execute(r"path-to-file", importOptions, GetMaps("aa579405"))
      # EndBlock

      In the documentation online and the space claim API documentation that came with the download, I cannot find any information on "GetMaps()" which seems to be the key. Additionally repeating the process manually with no other changes, the hex value in GetMaps changes (even though the result is the same). 

      • I have also tried importing and then using the OrientTo command as a work-around (see code snipit below), but this uses unit vectors to create the FoR and its unclear to me how these can be automatically linked to the origin

      Any help is greatly appreciated

      # Move Upto Selected Object
      selection = ComponentSelection.Create(GetRootPart().Components[1])
      upToSelection = Selection.Create(GetRootPart().CoordinateSystems[0].Axes[0])
      anchorPoint = Move.GetAnchorPoint(selection)
      moveFrame = Frame.Create(anchorPoint, Direction.Create(0.249572773159439, 0.176571112197779, -0.952121879401344), Direction.Create(0.176571112197779, 0.958453855953464, 0.224028677506199))
      axis = HandleAxis.X
      options = MoveOptions()
      options.CreatePatterns = False
      options.DetachFirst = False
      options.MaintainOrientation = False
      options.MaintainMirrorRelationships = True
      options.MaintainConnectivity = True
      options.MaintainOffsetRelationships = True
      options.Copy = False
      options.SnapAssociatedVertices = True
      result = Move.OrientTo(selection, upToSelection, moveFrame, axis, options)
      # EndBlock

       

    • Aniket
      Forum Moderator

      Hi Steven,

      Have you tried it without getmaps:

      DocumentInsert.Execute(r"D:\test.scdoc", importOptions)

      should work.

      -Aniket

      Forum Rules & Guidelines

    • Steven
      Subscriber

      Hi Aniket, 

      Using DocumentInser.Execute(...) with or without the "GetMaps" argument does import the object, but it does not associate it with the desired origin/reference frame

      If I manually click the origin so it is selected before running DocumentInsert.Execute(...) (either with or without "GetMaps") then it will be imported to the correct reference frame, but that cannot be automated (because then I would need to click each time before import)

      There must be a way to associate the import to a desired reference frame, since I am able to do it with the GUI, but I'm not sure of the command to make that association. I didnt see anything in the documents regarding the ImportOptions (although I could have missed it). 

      Is there a way to select an origin and make it active within a python script?

      • Aniket
        Forum Moderator

        Hi Steven, Is there any reason that this object cant be moved later to required position using move command?

        -Aniket

        Forum Rules & Guidelines

    • Steven
      Subscriber

      Hi Ankit, 

      The main reason is that at the moment I am placing it in the world frame of reference, then using the OrientTo and MoveTo commands to get it into the right place. But there is a tendancy for the OrientTo command to cause the axes to be anti-allgned (i.e. parallel but in the opposite directions) so my objects can be placed at the origin, but are often pointed in the wrong direction. 

      I can circumvent this by doing some additional checking and rotations before hand to make sure that the angle between the "upto" vector and "object" vector is less than 90 degrees, but a much simpler and more elegant solution would be to just have the object loaded into the frame of reference of my reference origin. 

      I know its possible to place the object in the reference origin's frame of reference with the GUI (this is standard practice) but I dont know how to do this with python scripting (or if its possible) - it always defaults to the world frame of reference.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.