Inventor Customization

Reply
Mentor
Posts: 174
Registered: ‎04-10-2008
Message 1 of 4 (155 Views)

Frustrating objectcollection problem... Items going missing

155 Views, 3 Replies
04-07-2011 11:13 PM

Hi all,

 

I've been working on a macro for quite a while now, and I'm REALLY close to completion. However I've just struck a problem I haven't seen before, and I'm struggling to understand.

 

To explain the macro very simply, it scans the activesheet in a drawing and generates a Collection Containing a list of LeaderNotes and Balloons, it then proceeds to replace all of them with the same LeaderNote/Balloon but on a different style. (I'm aware you can just change the style, but that's not the point). The way it works is for each item in the Collection it adds a new leader, and deletes the old one.

 

Problem is that when it deletes the old one, the corresponding entry from the Collection is also made invalid (It's still there, but all the values are "Application-defined or object-defined error"). I could live with this if it only corrupted the single corresponding value, however its corrupting 1 or 2 subsequent items in the object collection too.

 

I thought maybe I could Insert all the new leaders, then delete them all, but the same problem occurs when it goes back to delete everything.

 

Does anyone have any suggestions????? I'm at my wits end :smileymad:

___________________________________________
Gerrard Hickson
Inventor CAD Administrator || Autodesk Inventor 2012 Certified Professional
Autodesk AutoCAD 2012 Certified Professional|| Bachelor of Technology (Mechanical)

PointZero Design and Drafting
Distinguished Contributor
Posts: 130
Registered: ‎10-20-2001
Message 2 of 4 (154 Views)

Re: Frustrating objectcollection problem... Items going missing

04-07-2011 11:49 PM in reply to: gerhick

Iterating over a collection is invalidated if you change the collection during the iteration. Could you add the new ones first (add them to a separate collection), and then delete the entire original collection?

Mentor
Posts: 174
Registered: ‎04-10-2008
Message 3 of 4 (135 Views)

Re: Frustrating objectcollection problem... Items going missing

04-10-2011 04:02 PM in reply to: nmunro

I'm not entirely sure what you're suggesting there. The collection I've created doesn't get modified (by my code) once it's created. It simple is used as a reference to place the new leader on the sheet, and to delete the existing leader. It seems to me as though there is some 'link' between the leader on the sheet, and the item in the collection, but I've not seen this behaviour before... I had tried creating a duplicate collection (though I didn't delete the original) but it showed the same behaviour...

 

 

___________________________________________
Gerrard Hickson
Inventor CAD Administrator || Autodesk Inventor 2012 Certified Professional
Autodesk AutoCAD 2012 Certified Professional|| Bachelor of Technology (Mechanical)

PointZero Design and Drafting
Mentor
Posts: 174
Registered: ‎04-10-2008
Message 4 of 4 (130 Views)

Re: Frustrating objectcollection problem... Items going missing

04-10-2011 11:49 PM in reply to: gerhick

I seem to have found a suitable workaround for now. Once I've added all the new leaders from the collection on to the sheet, I can then go through and delete all the old leaders in reverse order (last item in Collection first).

___________________________________________
Gerrard Hickson
Inventor CAD Administrator || Autodesk Inventor 2012 Certified Professional
Autodesk AutoCAD 2012 Certified Professional|| Bachelor of Technology (Mechanical)

PointZero Design and Drafting

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube