Part Number Engraving

Part Number Engraving

cmcconnell
Collaborator Collaborator
532 Views
1 Reply
Message 1 of 2

Part Number Engraving

cmcconnell
Collaborator
Collaborator

Hello,

 

I will start by saying I am not a programmer - I usually copy/paste/modify/bang my head against the wall until I get what I need.

 

What I am trying to do today is create a rule that will allow me to select a face on a part and add the last 5 of our part number to where I clicked as a .01" cut extrusion (or emboss). If our part number changes, I would like this text to automagically update.

 

Using my current skillset (googlefu), here is what I have so far.

This first snippet grabs the last 5 of our pn (unless the override pn value is checked in a ilogic form) This all works as expected.

 

'Acts only on active document
Dim oDoc As Document = ThisApplication.ActiveDocument
If Not oDoc Is ThisDoc.Document Then Exit Sub

Dim oParams As Parameters
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	Dim oPartDoc As PartDocument = oDoc
	Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	oParams = oPartCompDef.Parameters
ElseIf oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oAssdoc As AssemblyDocument = oDoc
	Dim oAssCompDef As AssemblyComponentDefinition = oAssdoc.ComponentDefinition
	oParams = oAssCompDef.Parameters
End If

Dim oUserParams As UserParameters = oParams.UserParameters

Dim oMarking As String

'Create Marking Override Parameter
Try
	pMarkOvrd1 = oUserParams.Item("Marking_Override")

Catch
	'If no, create and populate values
	pMarkOvrd1 = oUserParams.AddByValue("Marking_Override", False, "BOOLEAN")
	Parameter.Param("Marking_Override").Comment = "Set by a Rule - Do Not Delete"
End Try

'Create MarkingValue Parameter
Try
	pMarkingValue1 = oUserParams.Item("MarkingValue")

Catch
	'If no, create and populate values
	pMarkingValue1 = oUserParams.AddByValue("MarkingValue", "", UnitsTypeEnum.kTextUnits)
	Parameter.Param("MarkingValue").Comment = "Set by a Rule - Do Not Delete"
End Try
	
''Set Custom property to parameter value
'iProperties.Value("Custom", "Marking") = Parameter("MarkingValue")


If Parameter("Marking_Override") = False Then
	oPartNumber = iProperties.Value("Project", "Part Number")

	'Grab last 5 characters of part number
	oMarking = Right(oPartNumber, + 5)

	iProperties.Value("Custom", "Marking") = oMarking
	
	'Set MarkingValue parameter to value of Marking property
	Parameter.Param("MarkingValue").Value = oMarking

	
	
End If

'Set MarkingValue parameter to value of Marking property
	Parameter.Param("MarkingValue").Value = iProperties.Value("Custom", "Marking")

Here is what I have so far in my feature creation rule:

oPartDoc = ThisApplication.ActiveDocument        

oPartDef = oPartDoc.ComponentDefinition

If oPartDoc.SelectSet.Count = 0 Then
	MsgBox("Please select a planar face before running command.",MessageBoxIcon.Error)
Else
	'Assume a face has been selected in the context of Assembly
	oFace = oPartDoc.SelectSet(1)
	
	'make sure it is a planar face
	If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
		
		oPlanarSurface = oFace.Geometry
		
			'add a sketch
		oSketch = oPartDef.Sketches.Add(oFace)
		oSketch.Name = "Marking"
			

			
		'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 
		'Set oTextPt = oSketch.ModelToSketchSpace(oPlanarSurface.RootPoint)
		oTextPt = oSketch.ModelToSketchSpace(CenterPt)
		
					
			'add the textbox
		oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, iProperties.Value("Custom", "Marking"))
		oSketchText.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
		oSketchText.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
		
	Else
		MsgBox( "please select a planar face.")
	End If
End If

So far this creates a sketch and calls it Marking. It place the sketch at the center of the closed profile of the face.

 

The changes I would like to make are:

  1. Rule prompts for selection (currently face needs to be preselected) - I do not know how to set up a selection prompt
  2. Sketch text should be placed at pick location - I do not know how to capture pick location
  3. Text needs to be extrude cut .01
  4. Text needs to update when value of parameter changes (currently it is placing static text in the text field - I need it to place linked text in the textbox)

If you can offer any suggestions that would be great - I will continue to dig around - if I get any further, I will post back here.

Mechanix Design Solutions inc.
533 Views
1 Reply
Reply (1)
Message 2 of 2

jaapschreuder
Contributor
Contributor

I would create a sketch on a plane that you create from a 'starting face'

In this sketch you can then find a position (maybe a fixed point in another construction sketch)
In this sketch you'll have your startpoint, and by "edit coordinate system" you can align the direction you prefer.

In this sketch make a (TEXT) that is linked to your <MODEL_PARAMETER>.
Assuming you will always want this embos on your part, no need to disable the feature.

Changing the position is changing the plane you first created to another face you prefer