Automatically generate extrusion of part number

Automatically generate extrusion of part number

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

Automatically generate extrusion of part number

Anonymous
Not applicable

Hello Everyone,

 

For my current job I'm setting up inventor for the engineering department. I've found a lot online, but there is one thing I'm still trying to find out. When using Solidworks a few years ago, someone made a 'tool', so that when you activated it and then clicked on a face of a (sheet metal) part, it created an extrusion (of abt 0.1 mm) of the part number. That way it got engraved with lasercutting (and was visible in the part itself)

Does anyone have an idea wheteher this is possible in inventor with  ilogic or a macro? Thanks in advance,

 

Regards, Niels

0 Likes
1,202 Views
8 Replies
Replies (8)
Message 2 of 9

johnsonshiue
Community Manager
Community Manager

Hi! I believe you want to etch the part number right? On Inventor 2018 and later, you can convert sketch text to thin geometry. Simply create a sketch and insert the part number. Right-click on the text -> Convert to Geometry.

The text will be converted to single line geometry (depending on fonts). Then you can export it to DXF.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hello,

 

Thanks for the quick reply! And yes, it's for etching a part number. Unfortunately we're working with quite an old version at the moment.. But even when we're gonna update to for example 2018, I'd still like to avoid having to execute these separate actions, but combine them (create sketch; insert part number; extude/convert to geo) into one 'button' or form. But maybe that's a bit too complex..

 

Niels

0 Likes
Message 4 of 9

paul.hurley
Participant
Participant

Hi Niels,

 

Are you still in need of this, are you happy with a small extrusion for the part No & and where on the face would you want it? I think i might already have made a tool for this.

 

Can you post a simple example of the results you want on a part.

 

Thanks Paul

0 Likes
Message 5 of 9

loekvbrc
Observer
Observer

@paul.hurley 

@Anonymous 

@johnsonshiue 

I thing this is exactly what i am looking for, and cant find it anywhere, il insert a foto of a part, but for this multibody part i had to make a sketch, place text, type it, extrude it, al these action take time and leave opportunity  for mistakes, i want a single function or button to rapidly cut a 0,1 extrudecut in my parts,(the extrude cut must be 0,1 because the guidline that”247tailorsteel” gives)

see foto,https://imgshare.io/image/pxWKuY

Thanks a lot for your time

 

 

0 Likes
Message 6 of 9

R.Mabery
Advocate
Advocate

Give this a try....it should be close to what you want.

 

Class Etching

Shared bStillSelecting As Boolean
Shared oModelPoint as Point 
Shared oModelFace As Face

	Sub Main()
		' Declarations
		bStillSelecting = True
		
		Dim oPartDoc as PartDocument
		Try
			oPartDoc = ThisApplication.ActiveDocument
		Catch ex as Exception
			Return
		End Try
		
		Dim oTG as TransientGeometry
		oTG = ThisApplication.TransientGeometry
		
		' Check for existing features
		Dim bExistingSketch As Boolean = False
		Dim oExistSketch as PlanarSketch
		For each oExistSketch in oPartDoc.ComponentDefinition.Sketches
			If oExistSketch.Name = "Engraving_Sketch" Then bExistingSketch = True 
		Next 
		
		Dim bExistingWPO As Boolean = False
		Dim oExistWPO as WorkPoint
		For each oExistWPO in oPartDoc.ComponentDefinition.WorkPoints
			If oExistWPO.Name = "Engraving_Point" Then bExistingWPO = True 
		Next 
		
		Dim bExistingFeature As Boolean = False
		Dim oExistFeature as ExtrudeFeature
		For each oExistFeature in oPartDoc.ComponentDefinition.Features.ExtrudeFeatures
			If oExistFeature.Name = "Engraving_Feature" Then bExistingFeature = True 
		Next 
		
		' If existing, exit rule
		If bExistingSketch OR bExistingWPO OR bExistingFeature Then Return
		
		' Get the camera from the view. 
		Dim oCamera As Camera 
		oCamera = ThisApplication.ActiveView.Camera
		
		' Get perspective of existing view 
		Dim bPerspectiveCamera as Boolean 
		bPerspectiveCamera = oCamera.Perspective
		
		' Set camera to ortho
		oCamera.Perspective = False
		oCamera.Apply
	 
		' Start InteractionEvents
		Dim oInteraction  As InteractionEvents 
		oInteraction = ThisApplication.CommandManager.CreateInteractionEvents
		
		oInteraction.StatusBarText = "Select face at point"

		Dim oMouse As MouseEvents
		oMouse = oInteraction.MouseEvents
		AddHandler oMouse.OnMouseClick  ,AddressOf oMouse_OnMouseDown 

		oInteraction.Start
		
		Do While bStillSelecting
			ThisApplication.UserInterfaceManager.DoEvents
		Loop
		
		' Stop InteractionEvents
		oInteraction.Stop()
		ThisApplication.CommandManager.StopActiveCommand
		bStillSelecting = False
		
		' Create workpoint
		Dim oWPO as Workpoint 
		If Not oModelPoint Is Nothing Then
			oWPO = oPartDoc.ComponentDefinition.WorkPoints.AddFixed(oModelPoint)
			oWPO.Name = "Engraving_Point"
			oWPO.Visible = False
		Else
			Return 
		End If
		
		' Create Sketch
		Dim oEngravedSketch As PlanarSketch
		oEngravedSketch = oPartDoc.ComponentDefinition.Sketches.Add(oModelFace, False)
		oEngravedSketch.OriginPoint = oWPO
		oEngravedSketch.Name = "Engraving_Sketch"
		
		Dim oSelectedPoint2d as Point2d
		oSelectedPoint2d = oTG.CreatePoint2d(0, 0)
		Trace.Writeline("iLogic: oSelectedPoint2d: " & oSelectedPoint2d.X & "," & oSelectedPoint2d.Y)
		
		' Add text
		Dim sTextEngraved As String
		sTextEngraved = iProperties.Value("Project", "Part Number")
		Trace.WriteLine("iLogic: sTextEngraved: " & sTextEngraved)
		
		Dim oTextBox As Inventor.TextBox
		oTextBox = oEngravedSketch.TextBoxes.AddFitted(oSelectedPoint2d, sTextEngraved)
		oTextBox.HorizontalJustification = kAlignTextCenter
		oTextBox.VerticalJustification = kAlignTextMiddle

		Dim dTextSize As Double
		dTextSize = 0.3175 ' value is in cm.  equals .125 in
		Dim sTextFont As String
		sTextFont = "SIMPLEX"
		oTextBox.FormattedText = "<StyleOverride Font = '" & sTextFont & "' FontSize = '" & dTextSize & "'>" & _
			sTextEngraved & "</StyleOverride>"
			
		' Create extrusion
		Dim oProfile As Profile
		Dim oExtrudeDef As ExtrudeDefinition
		Dim oExtrude As ExtrudeFeature
		
		oProfile = oEngravedSketch.Profiles.AddForSolid
		Trace.WriteLine("iLogic: oProfile Selected")
		
		oExtrudeDef = oPartDoc.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
		Call oExtrudeDef.SetDistanceExtent(0.1 , kNegativeExtentDirection)
		
		oExtrude = oPartDoc.ComponentDefinition.Features.ExtrudeFeatures.Add(oExtrudeDef)
		oExtrude.Name = "Engraving_Feature"
		
		' Set camera back to perspective if required
		If bPerspectiveCamera Then 
			oCamera.Perspective = bPerspectiveCamera
			oCamera.Apply
		End If

		' Clean up
		oMouse = Nothing
		oInteraction = Nothing
	End Sub

	Sub oMouse_OnMouseDown(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, oView As View)
		Trace.Writeline("iLogic: Debug oMouse_OnMouseDown Just Fired")

		Trace.Writeline("iLogic: oMouse_OnMouseDown 1")
		
		oModelPoint = GetPointOnFace(ModelPosition, oView)
		oModelFace = GetFace(ModelPosition, oView)
		
		bStillSelecting = False
	End Sub

	Sub oInteraction_OnTerminate()
		Trace.Writeline("iLogic: Debug oInteraction_OnTerminate Just Fired")

		bStillSelecting = False
	End Sub

	Function GetPointOnFace(oPoint As Point, oView As View) As Point
		Trace.Writeline("iLogic: Debug GetPointOnFace Just Fired")
		
		' Get the view direction, i.e. the vector pointing from the Eye to the Target
		Dim oEyeToTargetVector As Vector
		oEyeToTargetVector = oView.Camera.eye.VectorTo(oView.Camera.Target)
		
		' The vector that will take the Model Point from the
		' Target plane to the Screen plane is the opposite of oEyeToTargetVector
		Dim oModelToScreenPlane As Vector
		oModelToScreenPlane = oEyeToTargetVector.Copy
		oModelToScreenPlane.ScaleBy (-1)
		Call oPoint.TranslateBy(oModelToScreenPlane)
		
		Dim oPartDoc As PartDocument
		oPartDoc = oView.Document
		
		' Shoot a ray from the Screen plane towards the model along the view direction to
		' find the first object it hits and the intersection point
		Dim oObject**** As ObjectsEnumerator
		Dim oIntersectionPoints As ObjectsEnumerator
		Call oPartDoc.ComponentDefinition.FindUsingRay(oPoint, oEyeToTargetVector.AsUnitVector(), 0.001, oObject****, oIntersectionPoints)
		
		If oIntersectionPoints.Count > 0 Then
			Return oIntersectionPoints(1)
		End If
	End Function

	Function GetFace(oPoint As Point, oView As View) As Face
		Trace.Writeline("iLogic: Debug GetFace Just Fired")
		
		' Get the view direction, i.e. the vector pointing from the Eye to the Target
		Dim oEyeToTargetVector As Vector
		oEyeToTargetVector = oView.Camera.eye.VectorTo(oView.Camera.Target)
		
		' The vector that will take the Model Point from the
		' Target plane to the Screen plane is the opposite of oEyeToTargetVector
		Dim oModelToScreenPlane As Vector
		oModelToScreenPlane = oEyeToTargetVector.Copy
		oModelToScreenPlane.ScaleBy (-1)
		Call oPoint.TranslateBy(oModelToScreenPlane)
		
		Dim oPartDoc As PartDocument
		oPartDoc = oView.Document
		
		' Shoot a ray from the Screen plane towards the model along the view direction to
		' find the first object it hits and the intersection point
		Dim oObject**** As ObjectsEnumerator
		Dim oIntersectionPoints As ObjectsEnumerator
		Call oPartDoc.ComponentDefinition.FindUsingRay(oPoint, oEyeToTargetVector.AsUnitVector(), 0.001, oObject****, oIntersectionPoints)
		
		If oObject****.Count > 0 Then
			Return oObject****(1)
		End If
	End Function

End Class

Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 7 of 9

loekvbrc
Observer
Observer

Thanks a lot for the fast response,

Where should i place this code? Im not familiar with coding in inventor xd.

 

0 Likes
Message 8 of 9

R.Mabery
Advocate
Advocate

I run this as an external iLogic rule.  That way, it can be used against multiple documents.

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 9 of 9

loekvbrc
Observer
Observer

@R.Mabery wrote:

I run this as an external iLogic rule.  That way, it can be used against multiple documents.

 


Thanks, il try it tomorrow, 

thanks a lot for your time

0 Likes