API Created Section View: Sketch Not Deleted on Manual Remove

API Created Section View: Sketch Not Deleted on Manual Remove

BM_Ashraf
Advocate Advocate
234 Views
4 Replies
Message 1 of 5

API Created Section View: Sketch Not Deleted on Manual Remove

BM_Ashraf
Advocate
Advocate

Hello,

 

I'm programmatically creating sectional views on a drawing sheet using the Inventor API (specifically Sheet.DrawingViews.AddSectionView). As required by the API, I first create a DrawingSketch on the sheet on the FRONT VIEW and draw the section line within it before calling the AddSectionView method, passing the sketch as an argument.

The views are created successfully. However, I've observed a difference in behavior when these views are manually deleted through the Inventor user interface compared to manually created section views:

  • When a sectional view is created manually in Inventor and then manually deleted, the drawing sketch used for the section line is also automatically deleted.
  • When a sectional view is created using the API and then manually deleted, the SectionDrawingView object is removed, but the DrawingSketch and the section line geometry within it remain on the sheet.

This difference is causing orphaned sketches in my drawings when users manually delete views that were originally created by my API code.

My question is:

  1. Why does manual deletion not trigger the cleanup of the sketch when the sectional view was created via the API? Is there a difference in the type of link or dependency established between the sketch and the view by the manual command compared to the AddSectionView API method?
  2. Is there any way, using the Inventor API during the creation process (AddSectionView or other methods), to establish the same kind of link or dependency that causes the sketch to be automatically deleted when the user manually deletes the section view?

I am aware that I can explicitly delete the DrawingSketch using the API after deleting the SectionDrawingView programmatically. However, I am specifically interested in whether it's possible to replicate the automatic manual cleanup behavior seen with manually created views, or to understand the technical reason why this difference exists.

 

Tested on Inventor 2022

 

Any insights or guidance on this behavior would be greatly appreciated.

 

Thank you!

 

Befor delete

BM_Ashraf_0-1745305787797.png

 

After deleting the setional views

BM_Ashraf_1-1745306063719.png

 

 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
235 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @BM_Ashraf.  Quick question...when you created the sketch for the section line, did you use Sheet.Sketches.Add or did you use DrawingView.Sketches.Add?  I believe the DrawingSketch you create for that purposes should be 'owned' by the DrawingView, instead of owned by the Sheet.  I guess you could check the DrawingView.Sketches collection afterwards to make sure it is found within its collection afterwards, instead of within the Sheet.Sketches collection.  Just a thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

BM_Ashraf
Advocate
Advocate

Hi @WCrihfield ,

Thank you for your comment!
You are right, but I used DrawingView.Sketches.Add and the Sketch is already owend by the DrawingView (FRONT VIEW) see attached pic.

They way it's created by the API is very similar to maunal way. I'm just wondering the difference in behaviour when it comes to delete the section view.

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Looks like I didn't look at the images that closely before. 😏  My guess is that when we delete the section view manually, it executes a ControlDefinition with that SectionDrawingView object selected.  And most likely within the block of code that runs in reaction to that event it looks at the SectionDrawingView.SectionLineSketch to get that DrawingSketch object and delete that also, since it assumes that it is no longer needed.  It is common for UI related tools/commands to do more for us behind the scenes than we see or realize, making it seem odd when our Inventor API based attempts to do the same thing don't work exactly the same.  I don't know why there is a difference between the manual and API versions of the same thing, so just threw out something that seemed like it could play a part in the process, as somewhat of an educated guess.  I do know that some things do seem to get recorded differently by the 'Transactions' in Inventor (used by the UNDO control), when they get done manually versus when they are done by API code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

BM_Ashraf
Advocate
Advocate

Thanks @WCrihfield  for your thought!

Yeah, I totally agree with you that there are some hidden features or processes that are woking on Background. I checked if inventor adds any Attributes or something differently, but couldn't find and difference between the API created sketch and the Manually created sketch by the Section view Command.

I also tested it on Inventor 2026, and the problem is still there. Maybe it's needs to submitted to Ideas section

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!