Where Did I went Wrong

Where Did I went Wrong

Boopathi_Sivakumar
Collaborator Collaborator
622 Views
9 Replies
Message 1 of 10

Where Did I went Wrong

Boopathi_Sivakumar
Collaborator
Collaborator

Hello Guys,

I have started to Learn API for inventor. I am stuck with the bunch of codes . I Don't Know Where i Went wrong it throws me an error. I have tried lots of methods everything seems not working.

 

I been try to code it in Visual Studio but this one i have tested in the rule itself it is not working

i found the problem with the profiles, But don't know how to resolve it

 

Error.PNG

 

Dim App As Inventor.Application
App = ThisApplication

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

 Dim oCd As PartComponentDefinition
 Dim oTg As TransientGeometry
 

 oCd = oDoc.ComponentDefinition
        oTg = App.TransientGeometry
		
        Dim Ske As PlanarSketch
        Ske = oCd.Sketches.Add(oCd.WorkPlanes.Item(3))

        Dim oPo(7) As Point2d
        oPo(0) = oTg.CreatePoint2d(0, 0)
        oPo(1) = oTg.CreatePoint2d(5, 0)
        oPo(2) = oTg.CreatePoint2d(5, 2)
        oPo(3) = oTg.CreatePoint2d(4, 2)
        oPo(4) = oTg.CreatePoint2d(4, 3)
        oPo(5) = oTg.CreatePoint2d(5, 3)
        oPo(6) = oTg.CreatePoint2d(5, 5)
        oPo(7) = oTg.CreatePoint2d(0, 5)


        Dim Sk(7) As SketchLine
        Sk(0) = Ske.SketchLines.AddByTwoPoints(oPo(0), oPo(1))
        Sk(1) = Ske.SketchLines.AddByTwoPoints(Sk(0).EndSketchPoint, oPo(2))
        Sk(2) = Ske.SketchLines.AddByTwoPoints(Sk(1).EndSketchPoint, oPo(3))
        Sk(3) = Ske.SketchLines.AddByTwoPoints(Sk(2).EndSketchPoint, oPo(4))
        Sk(4) = Ske.SketchLines.AddByTwoPoints(Sk(3).EndSketchPoint, oPo(5))
        Sk(5) = Ske.SketchLines.AddByTwoPoints(Sk(4).EndSketchPoint, oPo(6))
        Sk(6) = Ske.SketchLines.AddByTwoPoints(Sk(5).EndSketchPoint, oPo(7))
        Sk(7) = Ske.SketchLines.AddByTwoPoints(Sk(6).EndSketchPoint, oPo(0))

        Dim oCol As ObjectCollection = App.TransientObjects.CreateObjectCollection
		
        oCol.Add(Sk(0))
        oCol.Add(Sk(1))
        oCol.Add(Sk(2))
        oCol.Add(Sk(3))
        oCol.Add(Sk(4))
        oCol.Add(Sk(5))
        oCol.Add(Sk(6))
        oCol.Add(Sk(7))

        Dim oPro As Profile
        oPro = Ske.Profiles.AddForSolid(True, oCol)

        Dim oRev As RevolveFeatures
        oRev = oCd.Features.RevolveFeatures

        Dim rev1 As RevolveFeature
        rev1 = oRev.AddFull(oPro, oCd.WorkAxes.Item(2), PartFeatureOperationEnum.kNewBodyOperation)

Thanks,

Boopathi

Boopathi Sivakumar
Sr Application Engineer
www.usamcadsoft.in
Facebook | Twitter | LinkedIn

0 Likes
Accepted solutions (2)
623 Views
9 Replies
Replies (9)
Message 2 of 10

bradeneuropeArthur
Mentor
Mentor

The sketch seems to be not closed!

 

Why I don't know.

 

Your code seems to be ok!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 10

Jef_E
Collaborator
Collaborator
Accepted solution

The profile isn't closed at the end. You can drag the last line away from the first. 

 

I fixed the faulty line.

 

Dim App As Inventor.Application
App = ThisApplication

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

 Dim oCd As PartComponentDefinition
 Dim oTg As TransientGeometry
 

 oCd = oDoc.ComponentDefinition
        oTg = App.TransientGeometry
		
        Dim Ske As PlanarSketch
        Ske = oCd.Sketches.Add(oCd.WorkPlanes.Item(3))

        Dim oPo(7) As Point2d
        oPo(0) = oTg.CreatePoint2d(0, 0)
        oPo(1) = oTg.CreatePoint2d(5, 0)
        oPo(2) = oTg.CreatePoint2d(5, 2)
        oPo(3) = oTg.CreatePoint2d(4, 2)
        oPo(4) = oTg.CreatePoint2d(4, 3)
        oPo(5) = oTg.CreatePoint2d(5, 3)
        oPo(6) = oTg.CreatePoint2d(5, 5)
        oPo(7) = oTg.CreatePoint2d(0, 5)


        Dim Sk(7) As SketchLine
        Sk(0) = Ske.SketchLines.AddByTwoPoints(oPo(0), oPo(1))
        Sk(1) = Ske.SketchLines.AddByTwoPoints(Sk(0).EndSketchPoint, oPo(2))
        Sk(2) = Ske.SketchLines.AddByTwoPoints(Sk(1).EndSketchPoint, oPo(3))
        Sk(3) = Ske.SketchLines.AddByTwoPoints(Sk(2).EndSketchPoint, oPo(4))
        Sk(4) = Ske.SketchLines.AddByTwoPoints(Sk(3).EndSketchPoint, oPo(5))
        Sk(5) = Ske.SketchLines.AddByTwoPoints(Sk(4).EndSketchPoint, oPo(6))
        Sk(6) = Ske.SketchLines.AddByTwoPoints(Sk(5).EndSketchPoint, oPo(7))
        Sk(7) = Ske.SketchLines.AddByTwoPoints(Sk(6).EndSketchPoint, Sk(0).StartSketchPoint)
		
        Dim oCol As ObjectCollection = App.TransientObjects.CreateObjectCollection
		
        oCol.Add(Sk(0))
        oCol.Add(Sk(1))
        oCol.Add(Sk(2))
        oCol.Add(Sk(3))
        oCol.Add(Sk(4))
        oCol.Add(Sk(5))
        oCol.Add(Sk(6))
        oCol.Add(Sk(7))

        Dim oPro As Profile
        oPro = Ske.Profiles.AddForSolid(True, oCol)

        Dim oRev As RevolveFeatures
        oRev = oCd.Features.RevolveFeatures

        Dim rev1 As RevolveFeature
        rev1 = oRev.AddFull(oPro, oCd.WorkAxes.Item(2), PartFeatureOperationEnum.kNewBodyOperation)


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 4 of 10

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, What is wrong in the code is that there are no coincidences in the startpoint of the first line, and the end point of the second line. Then there is the open profile. With this code, it should work well. Look at the detail marked in red to define the last line generated.

 

Dim App As Inventor.Application
App = ThisApplication

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

 Dim oCd As PartComponentDefinition
 Dim oTg As TransientGeometry
 

 oCd = oDoc.ComponentDefinition
        oTg = App.TransientGeometry
		
        Dim Ske As PlanarSketch
        Ske = oCd.Sketches.Add(oCd.WorkPlanes.Item(3))

        Dim oPo(7) As Point2d
        oPo(0) = oTg.CreatePoint2d(0, 0)
        oPo(1) = oTg.CreatePoint2d(5, 0)
        oPo(2) = oTg.CreatePoint2d(5, 2)
        oPo(3) = oTg.CreatePoint2d(4, 2)
        oPo(4) = oTg.CreatePoint2d(4, 3)
        oPo(5) = oTg.CreatePoint2d(5, 3)
        oPo(6) = oTg.CreatePoint2d(5, 5)
        oPo(7) = oTg.CreatePoint2d(0, 5)


        Dim Sk(7) As SketchLine
        Sk(0) = Ske.SketchLines.AddByTwoPoints(oPo(0), oPo(1))
        Sk(1) = Ske.SketchLines.AddByTwoPoints(Sk(0).EndSketchPoint, oPo(2))
        Sk(2) = Ske.SketchLines.AddByTwoPoints(Sk(1).EndSketchPoint, oPo(3))
        Sk(3) = Ske.SketchLines.AddByTwoPoints(Sk(2).EndSketchPoint, oPo(4))
        Sk(4) = Ske.SketchLines.AddByTwoPoints(Sk(3).EndSketchPoint, oPo(5))
        Sk(5) = Ske.SketchLines.AddByTwoPoints(Sk(4).EndSketchPoint, oPo(6))
        Sk(6) = Ske.SketchLines.AddByTwoPoints(Sk(5).EndSketchPoint, oPo(7))
        Sk(7) = Ske.SketchLines.AddByTwoPoints(Sk(6).EndSketchPoint, Sk(0).StartSketchPoint)

        Dim oCol As ObjectCollection = App.TransientObjects.CreateObjectCollection
		
        oCol.Add(Sk(0))
        oCol.Add(Sk(1))
        oCol.Add(Sk(2))
        oCol.Add(Sk(3))
        oCol.Add(Sk(4))
        oCol.Add(Sk(5))
        oCol.Add(Sk(6))
        oCol.Add(Sk(7))

        Dim oPro As Profile
        oPro = Ske.Profiles.AddForSolid(True, oCol)

        Dim oRev As RevolveFeatures
        oRev = oCd.Features.RevolveFeatures

        Dim rev1 As RevolveFeature
        rev1 = oRev.AddFull(oPro, oCd.WorkAxes.Item(2), PartFeatureOperationEnum.kNewBodyOperation)

 I hope this helps. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 10

Jef_E
Collaborator
Collaborator

@Sergio.D.Suárez community has changed it seems last time I asked a question it takes weeks for a answer now he gets 2 in 3min.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 10

Sergio.D.Suárez
Mentor
Mentor

Sorry, I assure you that I did not see your publication until after re-entering the publication. That was very close! I send you a warm greeting!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 7 of 10

bradeneuropeArthur
Mentor
Mentor

I did not see this post till now/today!

What is the issue?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 10

Boopathi_Sivakumar
Collaborator
Collaborator

@Jef_E  @Sergio.D.Suárez 

Thanks for the answer now i understand the problem, I am curious about how you guys find out the sketch is not closed it is it in the error page or by already faced this issue Smiley LOL

 

Cheers,

Boopathi

Boopathi Sivakumar
Sr Application Engineer
www.usamcadsoft.in
Facebook | Twitter | LinkedIn

0 Likes
Message 9 of 10

bradeneuropeArthur
Mentor
Mentor

move the line manually!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 10

Sergio.D.Suárez
Mentor
Mentor

Copying only this segment of your code, then pulls as @bradeneuropeArthur mentions, and your sketch adjusts as the image shows

 

Dim App As Inventor.Application
App = ThisApplication

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

 Dim oCd As PartComponentDefinition
 Dim oTg As TransientGeometry
 

 oCd = oDoc.ComponentDefinition
        oTg = App.TransientGeometry
		
        Dim Ske As PlanarSketch
        Ske = oCd.Sketches.Add(oCd.WorkPlanes.Item(3))

        Dim oPo(7) As Point2d
        oPo(0) = oTg.CreatePoint2d(0, 0)
        oPo(1) = oTg.CreatePoint2d(5, 0)
        oPo(2) = oTg.CreatePoint2d(5, 2)
        oPo(3) = oTg.CreatePoint2d(4, 2)
        oPo(4) = oTg.CreatePoint2d(4, 3)
        oPo(5) = oTg.CreatePoint2d(5, 3)
        oPo(6) = oTg.CreatePoint2d(5, 5)
        oPo(7) = oTg.CreatePoint2d(0, 5)


        Dim Sk(7) As SketchLine
        Sk(0) = Ske.SketchLines.AddByTwoPoints(oPo(0), oPo(1))
        Sk(1) = Ske.SketchLines.AddByTwoPoints(Sk(0).EndSketchPoint, oPo(2))
        Sk(2) = Ske.SketchLines.AddByTwoPoints(Sk(1).EndSketchPoint, oPo(3))
        Sk(3) = Ske.SketchLines.AddByTwoPoints(Sk(2).EndSketchPoint, oPo(4))
        Sk(4) = Ske.SketchLines.AddByTwoPoints(Sk(3).EndSketchPoint, oPo(5))
        Sk(5) = Ske.SketchLines.AddByTwoPoints(Sk(4).EndSketchPoint, oPo(6))
        Sk(6) = Ske.SketchLines.AddByTwoPoints(Sk(5).EndSketchPoint, oPo(7))
        Sk(7) = Ske.SketchLines.AddByTwoPoints(Sk(6).EndSketchPoint, oPo(0))

 

0.jpg


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn