Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mark feature with convert to geometry

3 REPLIES 3
Reply
Message 1 of 4
romu51
251 Views, 3 Replies

Mark feature with convert to geometry

Hi, 

I'm struggling to get the converted geometries from a text box to get added to the selection. 

i picked up the rule from another thread. 

if i comment out line 69 to 73, the rule works. 

Ideally i'd also like to just use the <Part number> iproperty in the text box rather than create a custom property. 

 

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 "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 TextBox
		    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0.5, 1), sText)
			
			

'==================== Creating an Objectcollection to be Marked ======================

    Dim oSketchObjects As ObjectCollection
    oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
       
'	 Get all entities In the sketch
	Dim oEntities As Object
	'Dim oSketchText As TextBox
	
	oTextBox.ConvertToGeometry("ISO")
	
	For Each oEntities In oSketch.SketchEntities
   		oSketchObjects.Add(oEntities)
		Next
    For Each oSketchText In oSketch.TextBoxes
        oSketchObjects.Add(oSketchText)
		Next

'	Dim oSketchEntity As Object 

'For Each oSketchEntity In oTransientGeometry
'    oSketchObjects.Add(oTransientGeometry) 
'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
	'oTextBox.ConvertToGeometry("ISO")
	oMark = oMarkFeatures.Add(oMarkDef)
	
'====================   
	
End Sub

 

 

3 REPLIES 3
Message 2 of 4
romu51
in reply to: romu51

I'm not getting interest with this... does this mean it can't be done? Autodesk people... plz help. thanks!

 

Message 3 of 4
A.Acheson
in reply to: romu51

Hi @romu51 

Can you explain where you would like assistance? 

You comment out line 69 to 73 can you explain where that is? There is no numbers in the code block you pasted. In order to show the numbers you need to use the dedicated editor in the posting toolbar which can  found with button </> , if these lines are not required you can remove them. I am assuming there are the mark feature lines and you are using an older version of inventor.

 

For the partnumber you can just remove the custom iproperty lines.

' ===================== 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

 

On this line set the text to the part number iproperty.

 

sText = iProperties.Value("Project", "Part Number")

 

If you have any other issues please share the modified code and any errors your seeing using the more info tab of the error message box. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 4
romu51
in reply to: romu51

Thanks for the reply.

See below for a tidied up version of the rule. 

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 Text With simple String As Input. 

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim sText As String
sText = iProperties.Value("Project", "Part Number")
Dim oTextBox As Inventor.TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0.5, 1), sText)
oTextBox.FormattedText = "<StyleOverride FontSize = '0.5'>" & sText & "</StyleOverride>"

oTextBox.ConvertToGeometry("ISO")

'	' Start the feature command
ThisApplication.CommandManager.ControlDefinitions.Item("PartMarkingCmd").Execute()

End Sub

 

 At the end, I'm executing the command to keep me going but ideally the MarkFeature should pickup the converted geometries and be ok. 

 

Edit: I'm on AIV 2023.3

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report