TAGGED: api, python-scripting, script, spaceclaim, speos
-
-
November 2, 2023 at 6:21 pm
Steven
SubscriberHello, 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"))
# EndBlockIn 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Â
-
November 3, 2023 at 7:32 am
Aniket
Forum ModeratorHi Steven,
Have you tried it without getmaps:
DocumentInsert.Execute(r"D:\test.scdoc", importOptions)
should work.
-Aniket
-
November 3, 2023 at 8:55 am
Steven
SubscriberHi 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?-
November 3, 2023 at 11:38 am
Aniket
Forum ModeratorHi Steven, Is there any reason that this object cant be moved later to required position using move command?
-Aniket
-
-
November 3, 2023 at 12:11 pm
Steven
SubscriberHi 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.
-
- The topic ‘Import object into user created origin reference frame (scripting)’ is closed to new replies.
-
3492
-
1057
-
1051
-
965
-
942
© 2025 Copyright ANSYS, Inc. All rights reserved.