- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello There,
Im having trouble getting my code right for Mark(ing) (the new function in 2023) my filenameNumber, to engrave with the laser. The code is working partly, the mark can't be made and I don't know why.
Please see my code below and advise me what is going wrong. I also attached the IPT file which I used.
Thank You in Advance
The Error Message i get is:
Error on line 97 in rule: YY_Mark_Tekeningnummer, in document: 97221181-0000 - Markfunction for Engraving.ipt
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
The Code is:
Sub Main() '=================================== 'This Is a Ilogic Rule To create a Mark From a textbox For engraving 'It is made with help from internet but NOT WORKING RIGHT ! 'I'm getting the message : 'Error On line 90 in rule: YY_Mark_Tekeningnummer, In document: 97221181-0000 - Markfunctie Nummer Filename.ipt 'Unable To cast COM Object Of type 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). ' PLEASE HELP '=================================== ' 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(1, 1), sText) '==================== Creating an Objectcollection to be Marked ====================== Dim oSketchObjects As ObjectCollection oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection ' Get all entities in the sketch Dim oSketchEntity As SketchEntity For Each oSketchEntity In oSketch.SketchEntities oSketchObjects.Add(oSketchEntity) 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(oSketchEntity, oMarkStyle) ' Create a mark feature. Dim oMark As MarkFeature oMark = oMarkFeatures.Add(oMarkDef) '==================== End Sub
Solved! Go to Solution.