Message 1 of 7
Insert partnumber on a surface
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there
Isn't it possible to insert Partnumber on a surface as text with ilogic code.
I have found the following on the net and it works almost as desired, but the problem is that the text is not updated if you change Partnumber under iProperties.
I really hope someone has a solution.
This is the code i found:
Sub Main()
'===================================
'This Is a Ilogic Rule To create a Mark From a textbox For engraving
'===================================
' 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
'================ Pasted to pick the face where the Mark has to come ============================
'Select Face and Edges to dimension sketch circles from
Dim oFrontFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Text On")
'============================================================
' Create a new sketch on this face
oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, _
oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))
' Determine where in sketch space the point (0.5,0.5,0) is.
Dim oCorner As Point2d
oCorner = oSketch.ModelToSketchSpace(oTransGeom.CreatePoint(0.5, 0.5, 0))
' ===================== Create a Custom Parameter in Iproperties "Partnummer"======================
'Creating Custom IProperty with filenumber in it calling it Partnummer
iProperties.Value("Custom", "Partnummer") = ThisDoc.FileName(False) 'false = without extension
iProperties.Value("Custom", "Partnummer") = (Left(ThisDoc.FileName(False),14))
'Creating a UserParameter Where the Partnummer value Is put In
Dim PropValue As String = iProperties.Value("Custom", "Partnummer")
'updates the user-defined Text Parameter
TagName = PropValue
'================================ Create a textbox in the Sketch to place the Iporp Partnummer ====================
' 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 TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(1, 1), sText)
'==================== Creating an Objectcollection to be Marked ======================
Dim oSketchObjects As ObjectCollection
oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
' Get all entities in the sketch
Dim oSketchText As 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)
'====================
End Sub