Message 1 of 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, happy day. I have an ipt file and in it I have a simple drawing that comes ready on the sketch. I want to access my lines in this drawing. I found a code block. It works with ilogic but not on api. The error I get is not being able to access the ComponentDefinition property of the document. When I do this on the iam file, I can set it as AssemblyDocument and access it. When I try this after opening the ipt entity, it fails. How do I fix this problem and I can access my lines.
My have code the Ilogic
Sub Main()
sPointOneX = 15
sPointOneY = 35
sPointTwoX = 105
sPointTwoY = 35
' Now we have to convert "mm" to "cm", because Inventor is measuring in "cm"
sPointOneX = sPointOneX * 0.1
sPointOneY = sPointOneY * 0.1
sPointTwoX = sPointTwoX * 0.1
sPointTwoY = sPointTwoY * 0.1
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
' Use this line to pick the first sketch in part
Dim oSketch As Sketch = oCD.Sketches.Item(1)
' Or use this line to pick the sketch by name
'Dim oSketch As Sketch = oCD.Sketches.Item("Sketch1")
Dim oLine As SketchLine
Dim line3 As Inventor.SketchLine
Dim lines = oSketch.SketchLines
Dim tg = ThisApplication.TransientGeometry
Dim oNewLine As SketchLine
Dim oSketchLine As SketchLine = oSketch.SketchLines.Item(1)
oDoc.SelectSet.Clear
oDoc.SelectSet.Select(oSketchLine)
For Each oLine In oSketch.SketchLines
Dim OurLine As Boolean
If oLine.StartSketchPoint.Geometry.X = sPointOneX And oLine.StartSketchPoint.Geometry.Y = sPointOneY Then
OurLine = CheckSecond(oLine.EndSketchPoint)
oLine.Delete()
line3 = lines.AddByTwoPoints(tg.CreatePoint2d(1.5, 2), tg.CreatePoint2d(10.5, 2))
Else If oLine.StartSketchPoint.Geometry.X = sPointTwoX And oLine.StartSketchPoint.Geometry.Y = sPointTwoY Then
OurLine = CheckSecond(oLine.EndSketchPoint)
End If
If OurLine = True Then
oNewLine = oLine
Exit For
End If
Next
If Not oNewLine Is Nothing Then
MsgBox("We've got the line")
End If
End Sub
Private sPointOneX As Double
Private sPointOneY As Double
Private sPointTwoX As Double
Private sPointTwoY As Double
Private Function CheckSecond(oPoint As SketchPoint) As Boolean
If oPoint.Geometry.X = sPointOneX And oPoint.Geometry.Y = sPointOneY Then
Return True
Else If oPoint.Geometry.X = sPointTwoX And oPoint.Geometry.Y = sPointTwoY
Return True
End If
Return False
End Function
Solved! Go to Solution.