Refresh Command from VBA

Refresh Command from VBA

Anonymous
Not applicable
4,798 Views
16 Replies
Message 1 of 17

Refresh Command from VBA

Anonymous
Not applicable
Hi All

Can anyone tell me how to run the Refresh Command from a VBA program. I have a small program for building parametric parts that crashes Inventor 6, with no warning or error. If I run the Refresh command first manually, all is well. I would like to be able to run Refresh automatically from the program.

Thanks
0 Likes
4,799 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable
Off the top of my head you could try oApp.update If that doesn't work you might want to post your code here so we can debug it with you. Mike@RTSWright
0 Likes
Message 3 of 17

Anonymous
Not applicable
I would guess it could be done with a sendkeys. Refresh is not the same
as update so far as I know. Update updates all pending edits where as
Refresh does the equivalent of reloading the entire assembly without
unloading it. Of course you would want to save first.

MDB wrote:

> Off the top of my head you could try oApp.update If that doesn't work
> you might want to post your code here so we can debug it with you.
> Mike@RTSWright
0 Likes
Message 4 of 17

Anonymous
Not applicable
Exactly...I tried oApp.Update without success before. The problem occurs when you delete all part occurrences from an assembly, and try to create another inplace part with the same name. It appears that even if you delete ALL occurrences, Inventor does completely release it references to the part file. If you try this in Inventor, you get an error message that the part file with the same name is still open, and you can't save the new part. This is strange, because you get this same message even if you go in and delete the '.ipt' file from the disc. If you cancel the part creation, do a refresh, the part creation works fine. Refresh reloads the parts, and doesn't create the reference to the deleted part.

From VBA, this error isn't trapped, and I can't figure out how to check if this reference still exists. The result is a 'Serious Error', -loading segment.... and Inventor usually locks the system, but sometimes crashes Inventor. You have to 'End Process' with Inventor to recover, if the system locks. This problem existed in 5.3, also, so I'm pretty sure it doesn't have anything to do with the Shared or Semi-Isolated environments. Thanks Charles...I'll look into your 'Sendkey' suggestion.
0 Likes
Message 5 of 17

Anonymous
Not applicable
Perhaps ...

ThisApplication.ActiveDocument.Rebuild


Joe
--
0 Likes
Message 6 of 17

Anonymous
Not applicable
This isn't officially supported, but you can give
it a try.  You'll want to save the assembly before calling
this.

 

Private Declare Function SendMessage Lib
"user32" Alias "SendMessageA" (
_
                   
ByVal hwnd As Long, ByVal wMsg As Long,
_
                   
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_COMMAND =
&H111

 

Private Sub Refresh()
   
Dim rc As Long
    rc = SendMessage(oApp.MainFrameHWND,
WM_COMMAND, 43086, 0)
End Sub


--
Brian
Ekins
Autodesk Inventor API Product Designer


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
All

Can anyone tell me how to run the Refresh Command from a VBA program. I
have a small program for building parametric parts that crashes Inventor 6,
with no warning or error. If I run the Refresh command first manually, all is
well. I would like to be able to run Refresh automatically from the program.

Thanks

0 Likes
Message 7 of 17

Anonymous
Not applicable
Thanks Brian...Your unsupported code seems to work great. I have it carved up somewhat, and included in my program. This 'SendMessage' routine looks interesting...any chance we might see some 'Official' documentation on the use of it within Inventor VBA in the future? Thanks again.
0 Likes
Message 8 of 17

Anonymous
Not applicable
SendMessage is a Windows API function so it has nothing to do with the Inventor API. It's basic operation is to post a message to the Inventor application window.

Joe
--
0 Likes
Message 9 of 17

Ruffy85
Collaborator
Collaborator

Hey Guys, 

 

After 14 years i grab this topic again into the front and ask a question.

 

I have nearly the same problem like the Thread Creator. 

 

I try to change size (CC item) via VBA in my Tube and Pipe Asm but after the Routine finished the graphical Window dont update.

 

i use the update functions but only the graphic window do not update. The rest iprops, replace part and so on works great.

 

So i tried to use the function which @Anonymous posted but it dont work in vba. is there a way to transalte it it inventor vba?

 

i tried to you the 32 bit version with

 

 Public Declare PtrSafe Function SendMessageA Lib "user32" (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
                                                           ByVal wParam As LongPtr, lParam As Any) As LongPtr

 But it dont work.

 

Anyone knows how to to this?

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 10 of 17

Owner2229
Advisor
Advisor

Wow, 14 years! That must be new local necromancing record!

...

Anyway, try something like this:

 

ThisApplication.ActiveView.Update()

Or:

 

ThisApplication.ActiveDocument.Update()
ThisApplication.ActiveDocument.Update2(True)

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 11 of 17

Ruffy85
Collaborator
Collaborator

will i receive a prize for this? 😄

 

i will check your posposal this evening. but i think i use this functions actually.

 

i believe that tube and pipe is buggy. if you create tube with bends and after u have populated your route, you can change the parameters inside a pipesegment but nothign happens. they dont use the parameters...

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 12 of 17

salariua
Mentor
Mentor

Mike and Markus

 

this is a known bug on Tube and Pipe,

 

Please check Idea 42 on TP Overhaul found on Idea station

 

http://forums.autodesk.com/t5/inventor-ideastation/tube-and-pipe-overhaul/idi-p/5518269

 

42 – When using Change Size on pipe segments the screen doesn't refresh so you need to pan, zoom or run a different command to get the screen to refresh and show the change

 

Not sure why, and how to solve it but it needs addressing.

 

😞

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 13 of 17

Owner2229
Advisor
Advisor

Thanks, Adrian and also WOW, that's a lot of work you put in that bug hunting.

 


@salariua wrote:

...so you need to pan, zoom or run a different command to get the screen to refresh...

 


So maybe simply moving the camera would do? I guess it's worth a try.

 

Dim oCam As Inventor.Camera
Set oCam = ThisApplication.ActiveView.Camera
Call oCam.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kFrontViewOrientation
Call oCam.Apply()
Call oCam.Fit()
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 14 of 17

salariua
Mentor
Mentor

Thanks Mike,

 

not sure it's good or bad that I found all these bugs / improvements / missing functionality; sad part is that's not all. I just stopped adding to it because we would be getting negative comments and some people have told me they are not considering Tube and Pipe now that they see all those issues being present.

 

I have 130 total documented and replicable cases and I need to post them but I just don't have time.

 

It's not so bad for me because I need to zoom / pan to select the next pipe to change size but I hope Markus and others will find it useful and can help improve TP

 

@Ruffy85, can you give it a try? Is the code working?

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 15 of 17

Anonymous
Not applicable

Oops

0 Likes
Message 16 of 17

Ruffy85
Collaborator
Collaborator

Thanks.

 

But won´t work 😞

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 17 of 17

salariua
Mentor
Mentor

@Anonymous wrote:

Oops


 

don't apologize @Anonymous, I feel like accepting your answer now!

 

Feels like the one that fits best with this problem

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes