Hi There,
I am having trouble to make the Mark for Engraving on the face in the right direction and position.
Sometimes the mark is outside of the geometry. and the rule can't compleet.
This is not always the case.
GOAL:
I want to place the mark for engraving on a picted face at a certain point in a certain direction.
I've tried this to do with a direction vector which i copied from the forum.
Still I can't get it right on several geometries.
Please help me with this.
Sub Main()
'===================== DECLERATIONS ===============================
' a reference to the currently active document.
' This assumes that it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'=========================================================================
'Find Sketch named already For marking so the user can delete it
For Each oSketchCheck As PlanarSketch In oPartCompDef.Sketches
If oSketchCheck.Name = "MarkingSketch" Then
MessageBox.Show("A sketch named " & oSketchCheck.Name & " already exists. Please Delete this sketch", "Controle op MarkingSketch")
Return
End If
Next
'=========================================================================
'Select Face and Edges to place the textbox in a certain direction
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Textbox")
Dim oHorizontalEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Horizontal Edge of Tekeningnummer on Face")
Dim oVerticalEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Vertical Edge of Tekeningnummer on Face")
'Add Sketch and set sketch origin point to the stopVertex of the FrontEdge, this is where the TextBox starts
Dim oSketch As PlanarSketch
oSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oVerticalEdge
oSketch.OriginPoint = oHorizontalEdge.StopVertex
oSketch.NaturalAxisDirection = True
' ===================== Create a Custom Parameter in Iproperties "Tekeningnummer"======================
'Creating Custom IProperty with filenumber in it calling it Tekeningnummer
iProperties.Value("Custom", "Tekeningnummer") = ThisDoc.FileName(False) 'false = without extension
iProperties.Value("Custom", "Tekeningnummer") = (Left(ThisDoc.FileName(False),14))
'Creating a UserParameter Where the Tekeningnummer value Is put In
Dim PropValue As String = iProperties.Value("Custom", "Tekeningnummer")
'updates the user-defined Text Parameter
TagName = PropValue
'================================ Create a textbox in the Sketch to place the Iporp Tekeningnummer ====================
' Create Text With simple String As Input. Since this doesn't use
' any Text Overrides, it will Default To the active Text Style.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim sText As String
sText = TagName
Dim oTextBox As Inventor.TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0.5, 0.5), sText)
'Changing Font and/or size
Dim dTextSize As Double
dTextSize = 0.350 ' value is in cm. equals .125 in
Dim sTextFont As String
' sTextFont = "SIMPLEX"
oTextBox.FormattedText = "<StyleOverride Font = '" & sTextFont & "' FontSize = '" & dTextSize & "'>" & _
sText & "</StyleOverride>"
'==================== Creating an Objectcollection to be Marked ======================
Dim oSketchObjects As ObjectCollection
oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
' Get all entities in the sketch
Dim oSketchText As Inventor.TextBox
For Each oSketchText In oSketch.TextBoxes
oSketchObjects.Add(oSketchText)
Next
'==================== Creating the Mark on the textbox ======================
Dim oMarkFeatures As MarkFeatures
oMarkFeatures = oCompDef.Features.MarkFeatures
' Get a mark style.
Dim oMarkStyle As MarkStyle
oMarkStyle = oPartDoc.MarkStyles.Item(1)
' Create mark definition.
Dim oMarkDef As MarkDefinition
oMarkDef = oMarkFeatures.CreateMarkDefinition(oSketchObjects, oMarkStyle)
' Create a mark feature.
Dim oMark As MarkFeature
oMark = oMarkFeatures.Add(oMarkDef)
'====================
'Naming the sketch And markfeature For detection In future
oSketch.Name = "MarkingSketch"
oMark.Name = "Gravering Tekeningnummer"
Call ZoomAll
oPartDoc.Save
End Sub
Sub ZoomAll
'zoom all, this to be sure the part is in ISOmetrich position saved so it is ISO visible in explorer
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
End Sub
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
maybe you can change the way how you define the sketch. something like this:
'=========================================================================
'Select Face and Edges to place the textbox in a certain direction
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Textbox")
Dim oHorizontalEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Horizontal Edge of Tekeningnummer on Face")
Dim orignVertex As Vertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Select vertex")
Dim testVertex As Vertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter,
"Select a 2e vertex that is on a positive point in the sketch")
'Add Sketch and set sketch origin point to the stopVertex of the FrontEdge, this is where the TextBox starts
Dim oSketch As PlanarSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oHorizontalEdge
oSketch.OriginPoint = orignVertex
oSketch.NaturalAxisDirection = True
'Check if the testVertex has positive coordinates
Dim testPoint As Point2d = oSketch.ModelToSketchSpace(testVertex.Point)
If (testPoint.X <= 0 Or testPoint.Y <= 0) Then
oSketch.NaturalAxisDirection = False
End If
' ===================== Create a Custom Parameter in Iproperties "Tekeningnummer"======================
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 Jelte,
I'tried your code but it seems the vertex is not correct an all faces with a certain direction. See attached screenshot.
I'v attached the file i use to test.
Hope the hear from you, Thank you in advance
Hi Jelte,
I'tried your code but it seems the vertex is not correct an all faces with a certain direction. See attached screenshot.
I've attached the file I use to test.
Hope the hear from you, Thank you in advance.
The idea was that you select something like this:
The new sketch will be placed on the "plane"
The origin of the sketch will be placed on "1e vertex"
The x-axis of the sketch will be defined by the "horizontal edge"
The axes are then still not defined because it's not defined what is positive and negative from the origin. That will be defined by any point in the positive quadrant of the plane. That's why you need to select the "2e vertex". The best would be to choose a 2e vertex that is not on one of the axes. Points/vertexes on an axis have the coordinates (0, Y) or (X, 0). If 0 is positive or negative is always a point of discussion therefore you could better select a point that is not on coordinate with 0 for X or Y.
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
I found a bug in the code. Changes are on lines 49 to 50 and 78 to 83. This code will do a better job:
Sub Main()
'===================== DECLERATIONS ===============================
' a reference to the currently active document.
' This assumes that it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'=========================================================================
'Find Sketch named already For marking so the user can delete it
For Each oSketchCheck As PlanarSketch In oPartCompDef.Sketches
If oSketchCheck.Name = "MarkingSketch" Then
MessageBox.Show("A sketch named " & oSketchCheck.Name & " already exists. Please Delete this sketch", "Controle op MarkingSketch")
Return
End If
Next
'=========================================================================
'Select Face and Edges to place the textbox in a certain direction
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Textbox")
Dim oHorizontalEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Horizontal Edge of Tekeningnummer on Face")
Dim orignVertex As Vertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, "Select vertex")
Dim testVertex As Vertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter,
"Select a 2e vertex that is on a positive point in the sketch")
'Add Sketch and set sketch origin point to the stopVertex of the FrontEdge, this is where the TextBox starts
Dim oSketch As PlanarSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oHorizontalEdge
oSketch.OriginPoint = orignVertex
oSketch.NaturalAxisDirection = True
'Check if the testVertex has positive coordinates
Dim testPoint As Point2d = oSketch.ModelToSketchSpace(testVertex.Point)
If (testPoint.X <= 0) Then
oSketch.NaturalAxisDirection = False
End If
testPoint = oSketch.ModelToSketchSpace(testVertex.Point)
Dim positiveQuadrantIsOnPlane = (testPoint.Y >= 0)
' ===================== Create a Custom Parameter in Iproperties Tekeningnummer ======================
'Creating Custom IProperty with filenumber in it calling it Tekeningnummer
iProperties.Value("Custom", "Tekeningnummer") = ThisDoc.FileName(False) 'false = without extension
iProperties.Value("Custom", "Tekeningnummer") = (Left(ThisDoc.FileName(False), 14))
'Creating a UserParameter Where the Tekeningnummer value Is put In
Dim PropValue As String = iProperties.Value("Custom", "Tekeningnummer")
'updates the user-defined Text Parameter
TagName = PropValue
'================================ Create a textbox in the Sketch to place the Iporp Tekeningnummer ====================
' Create Text With simple String As Input. Since this doesn't use
' any Text Overrides, it will Default To the active Text Style.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim sText As String
sText = TagName
Dim oTextBox As Inventor.TextBox
If (positiveQuadrantIsOnPlane) Then
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0.5, 0.5), sText)
Else
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0.5, -0.5), sText)
End If
'Changing Font and/or size
Dim dTextSize As Double
dTextSize = 0.350 ' value is in cm. equals .125 in
Dim sTextFont As String
' sTextFont = "SIMPLEX"
oTextBox.FormattedText = "<StyleOverride Font = '" & sTextFont & "' FontSize = '" & dTextSize & "'>" & _
sText & "</StyleOverride>"
End Sub
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 Jelte,
Your remark :
"The best would be to choose a 2e vertex that is not on one of the axes. Points/vertexes on an axis have the coordinates (0, Y) or (X, 0). If 0 is positive or negative is always a point of discussion therefore you could better select a point that is not on coordinate with 0 for X or Y."
Now it is working on every plane in my testpart. I'm going to test it in our workflow and give your last code as solution.
If I find any trouble with it during our engineering I will post it.
Thank you very much for your help!!
Hi Jelte and other enthousiasts,
I'm still having trouble selecting any face and than engrave on that face.
I've attached the part which I used. The engraving is on it so you can see which face I choosed.
But I had to open the sketch and rotate the textbox to do so.
Please have a try to use the rule on that face. You will see that the mark can't be placed on that face
I hope you can solve this. Thank you in advance
Can't find what you're looking for? Ask the community or share your knowledge.