Create G - Code from sketch blocks using iLogic

Create G - Code from sketch blocks using iLogic

Thomas_Savage
Advisor Advisor
870 Views
6 Replies
Message 1 of 7

Create G - Code from sketch blocks using iLogic

Thomas_Savage
Advisor
Advisor

Hello,

 

I am looking for some help with an iLogic code.

 

My colleague uses G-Coder to create a code for our punch.

 

And i have placed the tools, which are sketch blocks, that he uses to get the center points, to get the x,y and z coordinates in to Inventor.

 

Would it be possible to extract the x, y and z coordinates from the sketch blocks using iLogic?

 

So he would not have to manually type each x,y and z coordinate.

 

I have attached the .ipt below.

 

Any help much appreciated.

 

Thomas.

 

 

Block iLogic.png

 



Thomas Savage

Design Engineer


0 Likes
Accepted solutions (3)
871 Views
6 Replies
Replies (6)
Message 2 of 7

clutsa
Collaborator
Collaborator
Accepted solution

I couldn't open your attachment (I think your Inventor is newer then mine.) I did just throw some random points on a sketch in a new part file and was able to get their X, Y, and Z coords with...

doc = ThisDoc.Document
compDef = doc.ComponentDefinition
oSketch = compDef.Sketches.Item(1) 'first sketch in file
For Each sketchPoint In osketch.SketchPoints
	MessageBox.Show("X=" & sketchPoint.Geometry3d.X & vbCr & "Y=" & sketchPoint.Geometry3d.Y & vbCr & "Z=" & sketchPoint.Geometry3d.Z, "Title")
Next

The results are in cm so you would have to do some math on them first if you need something else. Also you probably want to use some code from the "My Snippets" tab to write the data to a file of some kind rather then to just a message box.

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 3 of 7

Thomas_Savage
Advisor
Advisor

Hello,

 

Thank you for that. 

 

I see if i can get it working and get back to you.

 

Thomas.



Thomas Savage

Design Engineer


0 Likes
Message 4 of 7

Thomas_Savage
Advisor
Advisor

Hello,

 

This does work. I am going to try and get the X & Y data in to a text file now.

 

Thanks, 

 

Thomas.



Thomas Savage

Design Engineer


0 Likes
Message 5 of 7

Thomas_Savage
Advisor
Advisor

Hello,

 

I have created the code to send the X and Y coordinates to a text file.

 

But it sends each point individually, to individual text files.

 

I want all the X and Y coordinates in the same text file.

 

Can you tell me how to do that please. Code attached below:

 

SyntaxEditor Code Snippet

doc = ThisDoc.Document
compDef = doc.ComponentDefinition
oSketch = compDef.Sketches.Item(1) 'first sketch in file
For Each SketchPoint In osketch.SketchPoints

'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine("X=" & sketchPoint.Geometry3d.X & vbCr & "Y=" & sketchPoint.Geometry3d.Y & vbCr & "Z=" & sketchPoint.Geometry3d.Z)
oWrite.Close()


'open the file
ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")

Next

 

Thanks,

 

Thomas.

 



Thomas Savage

Design Engineer


0 Likes
Message 6 of 7

clutsa
Collaborator
Collaborator
Accepted solution
doc = ThisDoc.Document
compDef = doc.ComponentDefinition
oSketch = compDef.Sketches.Item(1) 'first sketch in file


'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")

For Each SketchPoint In osketch.SketchPoints
    oWrite.WriteLine("X=" & sketchPoint.Geometry3d.X & vbCr & "Y=" & sketchPoint.Geometry3d.Y & vbCr & "Z=" & sketchPoint.Geometry3d.Z)

Next
'open the file
ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.Close()

for each point you made a new text file... you just need to move your for loop after you create the text file (and move the file open and close after the next so you don't do each of those actions for each point too)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 7 of 7

Thomas_Savage
Advisor
Advisor
Accepted solution

Hello @clutsa

 

Thank you for that.

 

It placed them all in the same text file.

 

Thomas.



Thomas Savage

Design Engineer


0 Likes