detecting modelling changes

detecting modelling changes

omartin
Advocate Advocate
512 Views
4 Replies
Message 1 of 5

detecting modelling changes

omartin
Advocate
Advocate

Hello, I am trying to get the updated range box of a part after it has been edified.

but my returned results are always, the dimensions before entering a sketch.

If I edit the extrusion, then the returned values update as expected

My guess is it cant capture the updated the geometry on exiting the sketch, I also tried throwing in various part.Updates before printing the value but no luck.

any suggestions would be great!

I am just working in the vba editor right now, I have just a form with the following:

In the module I have declared:

Dim WithEvents ae As ApplicationEvents
Dim WithEvents PE As PartEvents
Dim p As PartDocument

 

 

on form load I have:

Private Sub UserForm_Initialize()
Set ae = ThisApplication.ApplicationEvents

Set p = ThisApplication.activeDocument

Set PE = p.ComponentDefinition.PartEvents
End Sub

 

I have been messing around with these two calls, but the returned value is always an edit behind

Private Sub ae_OnNewEditObject(ByVal EditObject As Object, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kAfter Then

Debug.Print "eidt object.." & p.ComponentDefinition.RangeBox.MaxPoint.X
End If

or

Private Sub PE_OnSurfaceBodyChanged(ByVal Context As NameValueMap, ByVal BeforeOrAfter As EventTimingEnum, HandlingCode As HandlingCodeEnum)
Debug.Print "surface change.." & p.ComponentDefinition.RangeBox.MaxPoint.X
End Sub
Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Accepted solutions (1)
513 Views
4 Replies
Replies (4)
Message 2 of 5

HideoYamada
Advisor
Advisor
Accepted solution

Hello omartin,

 
I tried OnDocumentChange event and got a change of the RangeBox value.
 
private void ApplicationEvents_OnDocumentChange(_Document DocumentObject, EventTimingEnum BeforeOrAfter, CommandTypesEnum ReasonsForChange, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
    HandlingCode = HandlingCodeEnum.kEventNotHandled;

    if (DocumentObject is PartDocument doc)
    {
        Debug.WriteLine("OnDocumentChange : " + doc.ComponentDefinition.RangeBox.MaxPoint.X);
    }
}
Result is...
OnDocumentChange : 2.95061836209214    <--- Editing the sketch started.
OnDocumentChange : 0
OnDocumentChange : 0
OnDocumentChange : 0
OnDocumentChange : 0
OnDocumentChange : 0
OnDocumentChange : 0
OnDocumentChange : 4.24891304244134 <--- Exited from the sketch.

Keep it mind...

1) HandlingCode must be set to kEventNotHandled.

2) You shoud check the value when BeforeOrAfter = kAfter and doc.ActivatedObject is Nothing.

     (If you use OnDocumentChange event)

 

Best Regards,

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 3 of 5

omartin
Advocate
Advocate

Cool! I should be able to work with this.

 

Thanks for the info Hideo !!

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 4 of 5

HideoYamada
Advisor
Advisor

I'm glad if I could you help.

And I more thing...

If you want to detect the part is changed or not, you can check ModelGeometryVersion instead of RangeBox.

 

Best Regards,

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 5 of 5

omartin
Advocate
Advocate

Thanks again Hideo, that is a very useful property I have never came across before, good to know!

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes