Automated stamp for laser cutting

Automated stamp for laser cutting

Anonymous
Not applicable
1,304 Views
8 Replies
Message 1 of 9

Automated stamp for laser cutting

Anonymous
Not applicable

I got a ton of files where I need to make part with partnumber (Last 5 letter of filename) and export to DXF.

I have searched the forum and web for examples and been copy & pasting alot.

 

So far I have been able to type partnumber on part and make an extrude thru. 

But I have now been stucked for several days.

 

My goal are:

-Place last 5 letters of filename on part.      DONE

 

-Change letters to a height around 25mm / 1in.     No solution

 

-Extrude the text.   Partly done. I have to select sketch for it to Work and would like only a few millimeters deep cut 

 

-Export the face as DXF with full filename of part name. No solution

 

For testing. Make a box and save it with a 6+ letter filename.

 

So far my ilogic code looks like this.

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 22504 StartFragment: 314 EndFragment: 22472 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

oAssDoc = ThisApplication.ActiveDocument        

oAssDef = oAssDoc.ComponentDefinition

oItemNo = Right(ThisDoc.FileName(False),5)

Dim oFace As Face
Dim oStyle As TextStyle


oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face") 

    'make sure it is a planar face
    If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
        
        oPlanarSurface = oFace.Geometry
        
        'add a sketch
        oSketch = oAssDef.Sketches.Add(oFace)    
            
        'trying to choose an appropriate point
        'assume this planar face has one edge loop only
        oEdgeLoop = oFace.EdgeLoops(1)
            
        oMinPt = oEdgeLoop.RangeBox.MinPoint 
        oMaxPt = oEdgeLoop.RangeBox.MaxPoint
            
        CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)    
            
        'get one point on the face and transform to the point2d on the sketch 
        oTextPt = oSketch.ModelToSketchSpace(CenterPt)
            
        oTest = oSketch.TextBoxes.AddFitted(oTextPt, oItemNo)
        
        
        oSketch = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face") 
        
        Dim oPartDoc As PartDocument
        oPartDoc = ThisApplication.ActiveDocument
        
        
        Dim oCompDef As PartComponentDefinition
        oCompDef = oPartDoc.ComponentDefinition
        
    
        ' Create a profile.
        Dim oProfile As Profile
        On Error Goto NoProfile
        oProfile = oSketch.Profiles.AddForSolid
        
        
        'set direction
        oDirection  = kSymmetricExtentDirection
        'set operation
        oJoinOrCut  = kCutOperation
        
        
        ' Create an extrusion 
        Dim oExtrude As ExtrudeFeature
        On Error Goto NoExtrude
        oExtrude = oCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent( _
        oProfile, oDirection, oJoinOrCut)
        
        
        ThisApplication.CommandManager.ControlDefinitions.Item("FinishSketch").Execute
        
        
        iLogicVb.UpdateWhenDone = True
        
        
        Exit Sub
        
        
        NoProfile:
        MessageBox.Show("No closed profile found", "iLogic")
        Return
        
        
        NoExtrude:
        MessageBox.Show("No extrusion created, check your inputs.", "iLogic")
        Return
                
        
                
            Else
                MsgBox( "please select a planar face!")
            End If

  

0 Likes
Accepted solutions (1)
1,305 Views
8 Replies
Replies (8)
Message 2 of 9

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

Welcome to the Autodesk User's Community..

 

iLogic needs, questions, and issue should be posted in the Inventor customization forum for best results.  I will have the moderator relocate your posting there to best suit your needs.

 

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

Message 3 of 9

clutsa
Collaborator
Collaborator

Here's what I come up with...

oPartDoc = ThisApplication.ActiveDocument        

oPartDef = oPartDoc.ComponentDefinition

oItemNo = Right(ThisDoc.FileName(False),5)

Dim oFace As Face
Dim oStyle As TextStyle


oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face") 

'make sure it is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

	oPlanarSurface = oFace.Geometry

	'add a sketch
	Dim oSketch As Sketch = oPartDef.Sketches.Add(oFace)    
	oSketch.Edit 'added sub to edit sketch

	'trying to choose an appropriate point
	'assume this planar face has one edge loop only
	oEdgeLoop = oFace.EdgeLoops(1)

	oMinPt = oEdgeLoop.RangeBox.MinPoint 
	oMaxPt = oEdgeLoop.RangeBox.MaxPoint
	    
	CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)    

	'get one point on the face and transform to the point2d on the sketch 
	oTextPt = oSketch.ModelToSketchSpace(CenterPt)

	'set textStyle
	Dim myTextStyle As TextStyle
	
	Dim oTest As Inventor.TextBox = oSketch.TextBoxes.AddFitted(oTextPt, oItemNo)
	oTest.Style.FontSize = 2.54 'font size in cm (1 In)
	oSketch.ExitEdit 'used this to close sketch edit

	' Create a profile.
	Dim oProfile As Profile
	On Error GoTo NoProfile
	oProfile = oSketch.Profiles.AddForSolid

	'set direction
	oDirection  = PartFeatureExtentDirectionEnum.kSymmetricExtentDirection
	'set operation
	oJoinOrCut  = PartFeatureOperationEnum.kCutOperation


	'Set extrude parameters
	Dim ExtDepth As String = "1mm" 'change depth of extrude here
	Dim oExtrudeDef As ExtrudeDefinition = oPartDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, oJoinOrCut)
	oExtrudeDef.SetDistanceExtent(ExtDepth,oDirection)
	
	' Create an extrusion 
	Dim oExtrude As ExtrudeFeature
	On Error GoTo NoExtrude
	oExtrude = oPartDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

	iLogicVb.UpdateWhenDone = True


	Exit Sub

	NoProfile:
	MessageBox.Show("No closed profile found", "iLogic")
	Return

	NoExtrude:
	MessageBox.Show("No extrusion created, check your inputs.", "iLogic")
	Return
Else
    MsgBox( "please select a planar face!")
End If

Not bad for cut and paste! I'm sure this won't work perfect the first time but let me know what isn't working and we can tweak the code from there. 

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

Custom Glyph Icon for iMates

Message 4 of 9

Anonymous
Not applicable

Ohh man clutsa

I was happy to see your imput.

You got me a big step further.

 

I have been copy/pasting all day..

 

It now make: 

-Extrude partnumber in the part     (sizing number don't work thu (see note below))

-Convert part to sheet metal

-Export a DXF file to same path as .ipt

 

Last task should be to exit/close the .ipt without saving. But it make a '.NET framework' error  (I tried  oDoc2.Close(True) )

 

It seems that the resizing is set AFTER the textbox is placed. So first time rule are executed the text stay small.

So your example above have to be execute twice to Work. Tried several hours to fix it, without succes. 😞

 

Is it also possible to set a specified font and angle?

 

The code are by far a pretty example of copy - paste.. but does the job, kinda 🙂

 

I have added a sample part with the rule attached. Please take a look.

 

BTW- What a pain to Work from that Rule editor. Do I really have to Google for documentation on all methods / description etc?

 

Clutsa, thanks ALOT for your help

0 Likes
Message 5 of 9

clutsa
Collaborator
Collaborator

@Henrik.Tietgen wrote:

 

BTW- What a pain to Work from that Rule editor. Do I really have to Google for documentation on all methods / description etc?

 


Are you used to working in VBA? You can use the object browser in VBA to help find object/method info. This screen cast was made for someone else but the idea is the same.

 

I'll look at your code but that might help you in the meantime.  

 

P.S. Great job with your posts... You do a great job explaining exactly what you need help with and we can see that you've made an effort to solve it yourself. So many more people would get answers if they followed your formula for posting questions.

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

Custom Glyph Icon for iMates

Message 6 of 9

clutsa
Collaborator
Collaborator
Accepted solution

I still can't get the angle of the text to work but this should get you even further...

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument        
Dim oTransMgr As TransactionManager = ThisApplication.TransactionManager
Dim oTrans As Transaction = oTransMgr.StartTransaction(oPartDoc,"DXF with partnumber") 'used to group commands so we can undo later 
oPartDef = oPartDoc.ComponentDefinition

oItemNo = Right(ThisDoc.FileName(False),5)

Dim oFace As Face
Dim oStyle As TextStyle


oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face") 

'make sure it is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

	oPlanarSurface = oFace.Geometry

	'add a sketch
	Dim oSketch As Sketch = oPartDef.Sketches.Add(oFace)    
	oSketch.Edit 'added sub to edit sketch
	
	'trying to choose an appropriate point
	'assume this planar face has one edge loop only
	oEdgeLoop = oFace.EdgeLoops(1)

	oMinPt = oEdgeLoop.RangeBox.MinPoint 
	oMaxPt = oEdgeLoop.RangeBox.MaxPoint
	    
	CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)    

	'get one point on the face and transform to the point2d on the sketch 
	
	oTextPt = oSketch.ModelToSketchSpace(CenterPt)

	'set textStyle
	Dim myTextStyle As TextStyle 
	For Each stl In oPartDoc.TextStyles 'this loop checks if the style has already been made (because i kept crashing in the middle)
		If stl.name = "MyNewTextStyle" Then
			myTextStyle = stl
			MessageBox.Show("myTextStyle found", "Title")
			Exit For
		End If
	Next
	If myTextStyle Is Nothing Then 
		myTextStyle = oPartDoc.TextStyles.Item(21).Copy("MyNewTextStyle")
		MessageBox.Show("myTextStyle copied", "Title")
	End If

	myTextStyle.FontSize = 1.54
	myTextStyle.Rotation = 0 'this line should take a double but fails if anything but 0 is entered

	Dim oTest As Inventor.TextBox = oSketch.TextBoxes.AddFitted(oTextPt, oItemNo, myTextStyle)
	
	'oTest.Style.FontSize = 1.54 'font size in cm (1 In)    
	
	oSketch.ExitEdit 'used this to close sketch edit


	
	
	
	' Create a profile.
	Dim oProfile As Profile
	On Error GoTo NoProfile
	oProfile = oSketch.Profiles.AddForSolid

	'set direction
	oDirection  = PartFeatureExtentDirectionEnum.kSymmetricExtentDirection
	'set operation
	oJoinOrCut  = PartFeatureOperationEnum.kCutOperation


	'Set extrude parameters
	Dim ExtDepth As String = "1mm" 'change depth of extrude here
	Dim oExtrudeDef As ExtrudeDefinition = oPartDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, oJoinOrCut)
	oExtrudeDef.SetDistanceExtent(ExtDepth,oDirection)
	
	' Create an extrusion 
	Dim oExtrude As ExtrudeFeature
	On Error GoTo NoExtrude
	oExtrude = oPartDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
	
	
    '  Convert to Sheet metal    ----------------------------------------------------------------------------------------------
	Dim oPartDoca As PartDocument
  	oPartDoca = ThisApplication.ActiveDocument

 	'Change Document.SubType to Sheetmetal
	 oPartDoca.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
	
	
	'  Create DXF file from Sheet metal and save with same filename + .dxf  ------------------------------
	
	' Get the active document.  This assumes it is a part document.
'    Dim oDoc As PartDocument - This was done at top as oPartDoc
'    oDoc = ThisApplication.ActiveDocument - This was done at top as oPartDoc

    ' Get the DataIO object.
    Dim oDataIO As DataIO
    oDataIO = oPartDoc.ComponentDefinition.DataIO

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"
	

	
    ' Create the DXF file.
    oDataIO.WriteDataToFile (sOut, ThisDoc.PathAndFileName(False) & ".dxf")  'ThisDoc.FileName(True)

	'    Back to folded part ---------------------------------------------------------------------------------------------------
	
	oDoc2 = ThisDoc.Document 'I think you could get rid of this stuff too but it works so i left it alone
	Dim	oSMDef As SheetMetalComponentDefinition 
	oSMDef = oDoc2.ComponentDefinition 
	oSMDef.FlatPattern.ExitEdit 
	oTrans.End 'end the transaction group
	Dim undoLast As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions("AppUndoCmd") 'set the undo command
	undoLast.Execute 'run the undo command
	'ThisDoc.Document.Close(True) - DON'T DO THIS - Caused catostrophic crash
	
	
	'---------------------------------------------------------------------
	
	iLogicVb.UpdateWhenDone = True
	
	
	
	
	
	Exit Sub

	NoProfile:
	MessageBox.Show("No closed profile found", "iLogic")
	Return

	NoExtrude:
	MessageBox.Show("No extrusion created, check your inputs.", "iLogic")
	Return
Else
    MsgBox( "please select a planar face!")
End If
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 9

clutsa
Collaborator
Collaborator
myTextStyle.Rotation = 90 * (PI/180) 'Inventor uses Radians
'only works at 90, 180, 270
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 8 of 9

Anonymous
Not applicable

Can't get your code to Work. 

I replaced my code with yours in my earlier attached Sample file. But it seems it stop working after creating the sketch.

 

After fighting with your code a bit. I went to my Sample code. Here I got the resizing text working.

First I only place a SPACE, then do resizing and after that I place the wanted number.

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 3379 StartFragment: 314 EndFragment: 3347 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Dim oTest As Inventor.TextBox =    oSketch.TextBoxes.AddFitted(oTextPt, " ") 'placing an empty textbox
    oTest.Style.FontSize = 1 '1,5 is too big without angling text. text outside face
    'oTest.Style.Rotation = 90 '  won't work
     oSketch.TextBoxes.AddFitted(oTextPt, oItemNo) ' placing number on part
    

 

Btw. great video link. That Object browser will help alot.

0 Likes
Message 9 of 9

clutsa
Collaborator
Collaborator
Dim myTextStyle As TextStyle 
	For Each stl In oPartDoc.TextStyles 'this loop checks if the style has already been made (because i kept crashing in the middle)
		If stl.name = "MyNewTextStyle" Then
			myTextStyle = stl
			'MessageBox.Show("myTextStyle found", "Title") '<-----------removed this line
			Exit For
		End If
	Next
	If myTextStyle Is Nothing Then 
		myTextStyle = oPartDoc.TextStyles.Item(21).Copy("MyNewTextStyle")
		'MessageBox.Show("myTextStyle copied", "Title") '<-----------removed this line
	End If

from my last post of code try removing the message boxes about the TextStyle and see if it runs thru...

adding new lines like that thru out the code might help identify where you're getting hung up at too

 

Edit: you could also try changing item(21) to item(1).... 21 existed in your sample that I opened but maybe that was still specific to all the TextStyles I have on my local somehow (shouldn't but I've seen odder things)

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

Custom Glyph Icon for iMates

0 Likes