×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Set up WithEvents structure, ChangeCustomPropertyNotify

Set up WithEvents structure, ChangeCustomPropertyNotify

Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
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 smile .

Can someone help me set up this WithEvents structure?

Thanks

Tobin Sparks
www.nov.com

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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.

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
Thanks for your response. It gives me hope smile . This is a little over my head. Just giving him a star never seems to really express my gratitude smile .

Thanks

Tobin Sparks
www.nov.com

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

???

-handleman, CSWP (The new, easy test)

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
who? what? I don't get it. smile

Tobin Sparks
www.nov.com

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
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 smile .

Thanks again for your response

Tobin Sparks
www.nov.com

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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)

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

Doesn't look like my work.

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
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

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
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

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

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)

RE: Set up WithEvents structure, ChangeCustomPropertyNotify

(OP)
handleman,

Thanks for your input. That seems to help.

 

Tobin Sparks
www.nov.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources