Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set up WithEvents structure, ChangeCustomPropertyNotify 1

Status
Not open for further replies.

Tobin1

Petroleum
Nov 9, 2007
176
Howdy,

I’m having difficulty setting up a WithEvents structure. I’ve used one previously, but, this seems to be a little different. The code I used previously was triggered by a user selection on a drawing sheet (views, notes, sheet etc.). This time I need to get an event from a change in the Custom Properties (Summary Information, Custom tab). I’m not sure if it’s even possible, but, according to what I reading in the SW API help, I should be able to.

My goal is to run a form with a ListBox that displays all of the existing Custom Properties, then, while the form is still showing, allow the user to open (Shift + p) and change the Custom Properties, then, when that window is closed the ChangeCustomPropertyNotify function is triggered in the macro. I will use that event to update the ListBox to the revised Custom Properties (automatic update triggered by the change in the custom properties). I know I can make a button to do the update, but, wanted to make it automatic.

I’ve attached the macro I’ve been experimenting with. I have a feeling I’m either close or way off :) .

Can someone help me set up this WithEvents structure?

Thanks


Tobin Sparks
 
Replies continue below

Recommended for you

One problem is that custom properties are a ModelDoc thing, but ModelDoc does not have events.

You ned to monitor for changes in active document, then set PartDoc, AssemblyDoc, or DrawingDoc accordingly. You will need to set up three sets of events to catch each type.

Don't forget to give handleman a star.
 
Thanks for your response. It gives me hope :) . This is a little over my head. Just giving him a star never seems to really express my gratitude :) .

Thanks

Tobin Sparks
 
I don't know if I follow what you're doing correctly, but take a look at what I have in this macro.

In the listbox to the side will list all configurations in the open part:
Global = Part level custom properties
Everything else = Configuration level custom properties
(I have sorting so with a new setup having only 00 thru 99 configuration names, I won't have the "default" part 00 shown in the list to supercede the "global" properties)

I took a minute and removed the configuration sorting. (Note that if you click a configuration name in the list it automatically adds properties if they don't exist. If they do it will pull that information and enter into the text boxes)

Might be good reference for whatever you're trying to do.

Good luck. It was a fun project getting that stuff working. If you're confused by all of the wierd stuff in my macro it's mostly sorting so it recognizes custom properties with any case sensitivity and deletes anything I'm not presently allowing. (Basically automated house cleaning to get old parts and bad practice up to snuff)

If you have any questions with it holler.

James Spisich
Design Engineer, CSWP
 
 http://files.engineering.com/getfile.aspx?folder=51d26171-3ff0-42f9-ac15-a348e0592601&file=JS_CUSTOM_PROPERTIES_w_Configs.swp
Oh and to run it, when you make a custom macro button

Select the method: PropCode.Main

Otherwise you won't get too far. =D

James Spisich
Design Engineer, CSWP
 
jspisich,

Very nice Company-specific Custom Properties macro. I noticed it runs ShowModal = True. So the user can't access any other windows until there finished with the macro. I need to run the macro ShowModal = False because the user may need to access the FeatureManager design tree or the SW Summary Information window to make changes. Then I'd like the macro to automatically update. Maybe I'm expecting to much for a macro :) .

Thanks again for your response

Tobin Sparks
 
Expect the world, but it may take some work to get there.

What is it exactly you're trying to accomplish? It looks like you're just doing custom property management yes?

Do you have a standard list of properties you use? Can you just dump these to individual textboxes instead of a list? What is the purpose for using this as listbox? etc, etc.

Just curious to get more of the back story than what you gave.

James Spisich
Design Engineer, CSWP
 
Events are definitely a bit tricky. And keeping your macro running and waiting for the user to do stuff is always a bit risky. You really have to think about all the possible ways that the user could screw up your macro - deleting things, switching the active document, closing files, etc.

That being said, I found this macro in my stash. I don't remember writing it, but I can't for the life of me remember where I got it. Maybe it was from the API support section of SW, or maybe from "the Schwarz." I dunno. Basically, all it does is beep or notify you with a MsgBox when the active document is rebuilt. The ActiveDocChangeNotify function is really important. It makes sure that the active document is always pointed to by either ListenerPartDoc, ListenerDwgDoc, or ListenerAssyDoc. I guess you know, you can only register for events inside UserForm code or in a Class Module. This macro includes code for both.

-handleman, CSWP (The new, easy test)
 
handleman,

It'll take me a while to look into the macro you uploaded.
Thanks


Jspisich,

Attached is our complete Custom Properties macro. Well - complete in the sense that it reflects our current engineering department practices and default Custom Properties (which change from time to time).

<What is the purpose for using this as listbox? etc, etc.>
The ListBox (only for Assembly and Part Docs) gives the user an immediate look into the existing Custom Properties, so he/she can determine if it contains mistakes that need to be repaired. If the mistakes are minor the user can just use the Apply button to add any missing default Custom Properties. We didn't want to make a macro that deleted anything, the user has to do that purposely.

I guess I'm just trying to get rid of the Reload button. Seems minor, but, would make the macro closer to what I consider complete.

Thanks

Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=61e78254-bd77-4794-be5d-2c6c21d259bc&file=07_NOV_Custom_Props.swp
TheTick,

<You need to monitor for changes in active document, then set PartDoc, AssemblyDoc, or DrawingDoc accordingly.>

This makes more sense to me now. In my experiment macro I'm just working with PartDoc for now. If I get that to work I'm sure I can do the rest.

Thanks

handleman,

As usual - very helpful information.
I was able to follow RebuildMonitor.swp to change my code to make it work - sort of. I can get RegenPostNotify2 to cause the WithEvents action to run properly, but, can't seem to get a reaction out of ChangeCustomPropertyNotify.

Attached is the almost working macro.

Anybody have any ideas why that might be?

Thanks



Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=bc09d957-a07b-4c37-a03d-9f2af1ee9884&file=WithEvents2.swp
In your Reload() subroutine you set the objects you're wanting to monitor = nothing. Don't set the app object or the partdoc object = nothing.

-handleman, CSWP (The new, easy test)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor