Move EOP (End of Part) down just one feature using VBA.

Move EOP (End of Part) down just one feature using VBA.

shastu
Advisor Advisor
1,839 Views
11 Replies
Message 1 of 12

Move EOP (End of Part) down just one feature using VBA.

shastu
Advisor
Advisor

Is there a way to just move the (End of Part) down one feature regardless of where it is in the browser using VBA?  I already know how to move it all the way to the top, but can't figure out how to get it to move down one feature from where it is currently located regardless of the type of feature that it is?  Seems like it should be simple, but I can't figure it out.

0 Likes
Accepted solutions (1)
1,840 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor

It looks like this in regular iLogic.

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oAfter As PartFeature
Dim oBefore As PartFeature
oDef.GetEndOfPartPosition(oAfter, oBefore)
oAfter.SetEndOfPart(False)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 12

shastu
Advisor
Advisor

Thanks, but I was looking for a solution in VBA.  I tried to modify it for VBA but I don't know how to modify the last two lines.  Not sure if the fourth line down is correct either.

 

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
Set PartComponentDefinition = oDoc.ComponentDefinition
Dim oAfter As PartFeature
Dim oBefore As PartFeature
oDef.GetEndOfPartPosition(oAfter, oBefore)
oAfter.SetEndOfPart (False)

 

0 Likes
Message 4 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Here is the VBA version.

Public Sub Move_EOP_Down_1()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    Dim oAfter As Object
    Dim oBefore As Object
    oDef.GetEndOfPartPosition oAfter, oBefore
    oBefore.SetEndOfPart (False)
End Sub

To move the EOP down run it like shown.

To move the EOP up, switch the last line to:

oAfter.SetEndOfPart(True)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 12

shastu
Advisor
Advisor

Thanks so much.  I hate not being able to figure this out on my own.  How did you know what to change?

0 Likes
Message 6 of 12

WCrihfield
Mentor
Mentor

Glad to have been of some service.

Just trial, error, researching other similar sounding posts, repeat...

I'm not as familiar with VBA as I am with iLogic, but it's not that bad to pick up as needed when we've got a great forum like this to reference.

Good luck in your future Inventor Customization pursuits. 🙂

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 12

shastu
Advisor
Advisor

Thanks for your help.  It is greatly appreciated.

0 Likes
Message 8 of 12

kimdohyun__
Explorer
Explorer

really useful information. I had been searching for it all day.
but it would be good to add an if-statement to prevent errors in case EOP reaches the end or the beginning of the tree.

I wrote it in version 2026.

 

move down

Sub main()
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim oAfter As Object
	Dim oBefore As Object
	
	oDef.GetEndOfPartPosition(oAfter, oBefore)
	If Not oBefore Is Nothing
		oBefore.SetEndOfPart (False)
	End If
End Sub

 

move up

Sub main()
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim oAfter As Object
	Dim oBefore As Object
	
	oDef.GetEndOfPartPosition(oAfter, oBefore)
	If Not oAfter Is Nothing
		oAfter.SetEndOfPart(True)
	End If
End Sub

 

0 Likes
Message 9 of 12

WCrihfield
Mentor
Mentor

Hi @kimdohyun__.  Since you brought these methods back to mind, and pointed out that they could use some error proofing, there is yet another 'check' missing besides just checking if the Before or After objects are 'Nothing'.  When we look at Inventor's online API help for that method (PartComponentDefinition.GetEndOfPartPosition), we see that those two objects can be either a feature or sketch.  So, we also need to check whether it is a 'PartFeature' or a 'Sketch', because the PartFeature object has the 'PartFeature.SetEndOfPart' method available to it, but the Sketch object does not.  And if you try to call a method to run that does not exist, that would also throw an error.  Attached are 2 text files containing similar code examples that can be used in iLogic rules.  Both include a single 'Sub Main' block of code, where the 'helper' methods are being called to run from, then the helper methods are defined below.  One is simpler, just containing the 4 additional independent methods.  The other wraps the helper methods in a Class block of code, for use in an externally referenced external rule, with the 'Straight VB Code' option turned on, and referencing it with the 'AddVbFile' line in the 'Header' of a regular rule.  (Link)  Though obviously not really that much help as it is.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

kimdohyun__
Explorer
Explorer

Thank you for responding to a topic that is quite old.

 

First, I am a complete beginner for iLogic. So, I'm not even sure if I fully understood your answer or not....

I only intended to use this in the Part environment, and I wanted to assign the move up command and the move down command to different shortcuts. However, I didn't know how to implement that using a single iLogicVB rule. So I split them up. (┬┬﹏┬┬)

 

Also, I wanted to move the End of Part marker up and down, even if it included a sketch. This is because during part design, I often keep a sketch visible by drawing construction lines to make it visually easier to understand. And if a sketch is at the end of the tree, it should still be possible to move the EOP below that sketch. I don't know why but that code didn't produce an error when moving past a sketch.

So... referring to the code in your last answer, I modified my existing code like this. Is it correct that it will work as I intended?

Dim oDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, Inventor.PartDocument)
If oDoc Is Nothing Then Return
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oAfter As Object = Nothing
Dim oBefore As Object = Nothing

oDef.GetEndOfPartPosition(oAfter, oBefore)
If Not oBefore Is Nothing
	oBefore.SetEndOfPart (False)
End If

I'm truly sorry to ask again, but could you also tell me how to assign separate shortcuts for the move up and move down commands using just one iLogic rule? I don't know what search terms to use to find the answer.

0 Likes
Message 11 of 12

WCrihfield
Mentor
Mentor

Ah, the shortcut angle...I had forgotten that little detail.  If you are planning on placing this into Inventor's ribbon somewhere as a button that you can click, or assigning a keyboard shortcut for running it, then I guess there is no good reason to have both methods in the same rule, because there is no way to include an 'input' into the rule from the button click or keyboard shortcut that would instruct it to use one specific method instead of another.  Even when using the older VBA macro system, the macro had to be a Sub routine (just does something without returning anything), not a Function routine (designed to return something), and it can not have any 'inputs', otherwise we could not create a ribbon button for it.  I think the same is still true for ribbon buttons for external iLogic rules, because a simple button click can not provide any input to the rule it runs.

And yes, I have observed the same behavior where it still works with sketches.  After a little more research I found the documentation supporting / explaining that.  In the world of object oriented coding, there are Types of objects, with each Type having its own set of properties, methods, & events associated with it.  And sometimes there are parent types (more generic with fewer properties, methods) and sub types (more specific, with more properties and such.  With that in mind, the Sketch object is the 'base type' (most generic, least specific), and its documentation does not include the 'SetEndOfPart' method.  However, if we look at one of its sub types like the PlanarSketch (constrained to a flat plane or flat face, and only exist within a 'model' file), which is what we most commonly use in a part, we can now see that method (PlanarSketch.SetEndOfPart).  The other main sub type of a generic Sketch is the DrawingSketch, which is also 2D, but only exists within drawing files, not within model files, so it will obviously not have that method in it that was meant for use within a part file.  Then there is the Sketch3D object type, which only exist in part files, not in assemblies or drawings.  It also has that method (Sketch3D.SetEndOfPart).  So, that extra check I mentioned is likely not really necessary after all.  😅

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 12

kimdohyun__
Explorer
Explorer

It’s really difficult! 😂 I guess I need to study more.

Since the code works for now, I’ll just leave it as is 🤣

Thank you so much for the detailed explanation.

0 Likes