Hi,
I am trying to automatically pull the X,Y,Z Coordinates from Custom Origin.
For Example,I have an Custom UCS for which the X,Y,Z coordinates has to be measured from.
I am getting correct values when measuring from Origin Center point. But for the custom UCS the Code generates the Wrong measurements as it doesn't sense the Vector Direction for the Positive and Negative Axis.
Can anyone please help to automate the above one?
I have attached picture and Output values.
I am new to ilogic so I would really appreciate for any help..
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
Hi @get2dpk. It is fairly difficult to follow your code without fully understanding what all is going on in your model space and what all your intent was when creating these things. Often when getting results that look like the bottom image in Picture4, it has to do with the Double data type, and not rounding results off to a reasonably short number of decimal places. What values did you intend to see in that scenario? Where is your custom UCS's origin in reference to the regular origin?
Wesley Crihfield
(Not an Autodesk Employee)
hi @WCrihfield ,
Thanks for the reply.
Please see below information for your Questions.
1.What all is going on in your model space and what all your intent was when creating these things.? - I am trying to automatically create a table listing X,Y,Z coordinates of workpoints from a custom point as datum. For example Usually In an Assembly/Part I will fix a datum point (not the same as Origin point) . create Workpoints on Holes, Ports, and measure them from the Custom datum manually.
2.It has to do with the Double data type, and not rounding results off to a reasonably short number of decimal place?- I have attached the Correct Values in the picture below. you can see these values varies more than the double limit. I think it has to do something with the Inventor vector Direction .
3.Where is your custom UCS's origin in reference to the regular origin?-picture attached
Hi @get2dpk. I had to create the model file for this scenario for myself, so I had something to test out my theories on. I just created the part, then used an iLogic rule to create the UCS on it at the same position and orientation as your model was. Then I wrote a new iLogic rule, from scratch, to analyze and measure the offsets between Origin & WorkPoints, and for the UCS origin to WorkPoints. My code works just fine, after a couple tweaks. I will post the results here, so they will hopefully help you figure things out the way you need them. I attached the Part (2022 version), and attached text files for both iLogic rules I used (also within the part).
Wesley Crihfield
(Not an Autodesk Employee)
hi @WCrihfield
Thanks for the Ilogic code. it works.😊
Still I see that User has to manually update the Code for name and the Instances of Workpoints. Here the code is written to 3 workpoints. so if we use 5 workpoints, we have to go to code and update code right?
Is there any way to measure all the available workpoints without user editing the code? I meant Inventor itself will recognize the number of Workpoints in the model ?
please refer the below image from old ilogic rule .(the values are wrong though). I didnot specify the number of workpoints. is it possible to do something similar to this in the Ilogic rule you made .
2. I cannot open the Ipt model you shared since I am using 2020. Also the Ilogic rule is not running for Assembly
Thanks in Advance!
If I understand correctly you want to get all work points relative to a UCS. And write the info to a csv file. In that case, try this iLogic rule. I changed the way the user needs to select the UCS. In my rule the user should select the UCS by clicking on it. In stead of selecting it from a list.
Sub Main()
Dim doc As PartDocument = ThisDoc.Document
Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure
Dim workPoints = doc.ComponentDefinition.WorkPoints
Dim origin = workPoints.Item("Center Point")
Dim ucs As UserCoordinateSystem = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kUserCoordinateSystemFilter,
"Select an UserCoordinateSystem")
Dim translationVector = ucs.Origin.Point.VectorTo(origin.Point)
Dim csvFileInfo As New IO.FileInfo(ThisDoc.PathAndFileName(False) & ".csv")
If csvFileInfo.Exists Then
csvFileInfo.Delete()
End If
Using csvWriter As IO.StreamWriter = csvFileInfo.CreateText()
' This will make sure Excel will reconise the column seperator
csvWriter.WriteLine("sep=,")
csvWriter.WriteLine("Name,X,Y,Z")
For Each workPoint As WorkPoint In workPoints
If (WorkPoint.IsCoordinateSystemElement) Then Continue For
Dim p As Point = WorkPoint.Point
p.TranslateBy(translationVector)
Dim x As Double = ConvertToInch(uom, p.X)
Dim y As Double = ConvertToInch(uom, p.Y)
Dim z As Double = ConvertToInch(uom, p.Z)
csvWriter.WriteLine(string.Format("{0}, {1}, {2}, {3}",workPoint.Name,x,y,z))
Next
End Using
End Sub
Private Function ConvertToInch(uom As UnitsOfMeasure, value As Double) As Double
value = uom.ConvertUnits(value, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)
Return Math.Round(value, 10)
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
hi Jeltehjong,
Thanks for the code! It works as I thought.😃
Could you Please help me with some Changes in your code
1.It will be handy if the User can specify the Folder Location to store the CSV File. so A Input Box for the Location will be great where user can specify the Folder while running the Code.
2.Also a Message pop up showing up coordinate Values at the end of the Automation.
3.Is it possible to bring the UCS selection in list instead of selecting it from window.(not mandatory)
Appreciate your Help!
What about this:
Sub Main()
Dim doc As PartDocument = ThisDoc.Document
Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure
Dim workPoints = doc.ComponentDefinition.WorkPoints
Dim origin = workPoints.Item("Center Point")
Dim systems = doc.ComponentDefinition.UserCoordinateSystems
Dim ucsNames = systems.Cast(Of UserCoordinateSystem).Select(Function(u) u.Name)
Dim name = InputListBox("Pick one", ucsNames, ucsNames.First(), "Reference Origin", "Center Point and UCS")
Dim ucs As UserCoordinateSystem = systems.Item(name)
Dim translationVector = ucs.Origin.Point.VectorTo(origin.Point)
Dim fileDialog As FileDialog
ThisApplication.CreateFileDialog(fileDialog)
fileDialog.DialogTitle = "Save points"
fileDialog.Filter = "Point Files (*.csv)|*.csv"
fileDialog.ShowSave()
Dim csvFileInfo As New IO.FileInfo(fileDialog.FileName)
If csvFileInfo.Exists Then
csvFileInfo.Delete()
End If
Using csvWriter As IO.StreamWriter = csvFileInfo.CreateText()
' This will make sure Excel will reconise the column seperator
csvWriter.WriteLine("sep=,")
csvWriter.WriteLine("Name,X,Y,Z")
For Each workPoint As WorkPoint In workPoints
If (WorkPoint.IsCoordinateSystemElement) Then Continue For
Dim p As Point = WorkPoint.Point
p.TranslateBy(translationVector)
Dim x As Double = ConvertToInch(uom, p.X)
Dim y As Double = ConvertToInch(uom, p.Y)
Dim z As Double = ConvertToInch(uom, p.Z)
csvWriter.WriteLine(String.Format("{0}, {1}, {2}, {3}", WorkPoint.Name, x, y, z))
Next
End Using
End Sub
Private Function ConvertToInch(uom As UnitsOfMeasure, value As Double) As Double
value = uom.ConvertUnits(value, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)
Return Math.Round(value, 10)
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Hi @JelteDeJong
I have been trying your Code and observed the Below issue
I see that the 2nd and 5th Column(Yellow Highlighted) Values are decimal numbers after X and Z Coordinates respectively
For Eg
-the Actual X coordinate dimension of WP2 from UCS1 is -51.52 , but it is splitting itself into two Columns
-the Actual Z coordinate dimension of WP2 from UCS1 is -11.395 , but it is splitting itself into two Columns
Could you please help in Correcting this Issue
appreciate your Help
Regards
Pradeep S
Hi @get2dpk. This is just an educated guess on my part, but since you are storing the values to a CSV (Comma Separated Values) file, and your numerical values use a comma as their decimal separator, instead of a period or dot, the Integer portion and decimal portion are being separated as separate values. You may have to format your values differently if you want to store them to a CSV file, or store them in something other than a CSV file.
Wesley Crihfield
(Not an Autodesk Employee)
I Expect that @WCrihfield is right. If you change the separator in the csv file to ; the problem is probably solved. try something like this:
Sub Main()
Dim doc As PartDocument = ThisDoc.Document
Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure
Dim workPoints = doc.ComponentDefinition.WorkPoints
Dim origin = workPoints.Item("Center Point")
Dim systems = doc.ComponentDefinition.UserCoordinateSystems
Dim ucsNames = systems.Cast(Of UserCoordinateSystem).Select(Function(u) u.Name)
Dim name = InputListBox("Pick one", ucsNames, ucsNames.First(), "Reference Origin", "Center Point and UCS")
Dim ucs As UserCoordinateSystem = systems.Item(name)
Dim translationVector = ucs.Origin.Point.VectorTo(origin.Point)
Dim fileDialog As FileDialog
ThisApplication.CreateFileDialog(fileDialog)
fileDialog.DialogTitle = "Save points"
fileDialog.Filter = "Point Files (*.csv)|*.csv"
fileDialog.ShowSave()
Dim csvFileInfo As New IO.FileInfo(fileDialog.FileName)
If csvFileInfo.Exists Then
csvFileInfo.Delete()
End If
Using csvWriter As IO.StreamWriter = csvFileInfo.CreateText()
' This will make sure Excel will reconise the column seperator
csvWriter.WriteLine("sep=;")
csvWriter.WriteLine("Name;X;Y;Z")
For Each workPoint As WorkPoint In workPoints
If (workPoint.IsCoordinateSystemElement) Then Continue For
Dim p As Point = workPoint.Point
p.TranslateBy(translationVector)
Dim x As Double = ConvertToInch(uom, p.X)
Dim y As Double = ConvertToInch(uom, p.Y)
Dim z As Double = ConvertToInch(uom, p.Z)
csvWriter.WriteLine(String.Format("{0};{1};{2};{3}", workPoint.Name, x, y, z))
Next
End Using
End Sub
Private Function ConvertToInch(uom As UnitsOfMeasure, value As Double) As Double
value = uom.ConvertUnits(value, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)
Return Math.Round(value, 10)
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Hello ,
I'm inventor user.
I wan't to create a macro or rule ilogic for obtain z position for each point .
For obtain X and Y position I use a hole table by cliking to the centermark .
My UCS is costumize.
I join you some capture
Thank to help me please.
Can't find what you're looking for? Ask the community or share your knowledge.