4:06 AM 3/10/2019 Help PleaseAnyone who knows the more complex VBA ?
When I close a file, I have several things I have to do, they are now all done by the VBA. I was able tofigure out. This Timer and the If-then-else seem to be way above my ability.I now have to remember to detach reference files before sending them in, but when I open and close the .dgn file while making changes I do not want to detach the reference then. Only upon completion of the .dgn. when I close for the last timebefore sending in my work.This is the simple Macro that detaches the reference file:Sub XrefDet() 'the () is the ( and ) but it looks funny ' 031019 - Detach Reference file CadInputQueue.SendCommand "Reference Detach All" End Sub
So I wanted to have an If-then-else that would time out in say 4-8seconds and it would equal a noor a strike say space bar and it = no, but you could put Y if you wanted it to detach. I am attaching the timer from the help file. I could not get to work myself, but this is it.
This example uses the Timer function to pause the application. The example also uses DoEvents to yield to other processes during the pause.
Dim PauseTime, Start, Finish, TotalTimeIf (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then PauseTime = 5 ' Set duration. Start = Timer ' Set start time. Do While Timer < Start + PauseTime DoEvents ' Yield to other processes. Loop Finish = Timer ' Set end time. TotalTime = Finish - Start ' Calculate total time. MsgBox "Paused for " & TotalTime & " seconds"Else EndEnd If
I also looked up the if-then-else and it is also attached.This example shows both the block and single-line forms of the If...Then...Else statement. It also illustrates the use of If TypeOf...Then...Else.
Dim Number, Digits, MyStringNumber = 53 ' Initialize variable.If Number < 10 Then Digits = 1ElseIf Number < 100 Then' Condition evaluates to True so the next statement is executed. Digits = 2Else Digits = 3End If ' Assign a value using the single-line form of syntax.If Digits = 1 Then MyString = "One" Else MyString = "More than one"
Use If TypeOf construct to determine whether the Control passed into a procedure is a text box.
Sub ControlProcessor(MyControl As Control) If TypeOf MyControl Is CommandButton Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is CheckBox Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is TextBox Then Debug.Print "You passed in a " & TypeName(MyControl) End IfEnd Sub
These are beyond my ability to under stand, I have tried on my own and spent a number of hours trying to get something even simple and than build from there. Any Help ? All I can say is thank you and offer some money for the help.
It is better to implement your task by using MDL because there is an existed event for file close. VBA is not very suitable for doing underlying works.
thank you, but I am not sure what MDL or how to use them
there was a VBA Routine already detaching the References, but at times I do not want them unloaded and I was going to use the if then to ask me if I wanted to detach the files and I could respond yes Y or No N or press any key like the space bar and it would not detach unless I specifically responded with a Y. not sure how I would use an MDL for this, but thank you for even giving a reply.
Version: MicroStation V8i SS 10
RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus
Richard Phillips said:Anyone who knows the more complex VBA ?
Remember that VBA is a Microsoft product, not exclusive to MicroStation. It's available on several different platforms, including the Microsoft Office suite. Your question is not directly related to MicroStation. If you search web sites that deal with VBA in general, you may find some hints and tips to get you on your way. The Excel community is especially active with VBA.
Yongan.Fu said:It is better to implement your task by using MDL
In this case, MDL would be a step too far, for several reasons.
Regards, Jon Summers LA Solutions
So if I understand the above correctly, all you want to do is give a user that choice to detach all reference files upon exiting a drawing?
Richard Phillips said: if I wanted to detach the files and I could respond yes Y or No N or press any key like the space bar and it would not detach unless I specifically responded with a Y.
When I key in Reference Detach All in Key-in window, MS will pop up a dialog to ask me this. So why do you still need to program? Please see my attached pic.
Yes, Sir I do not always want the Reference files detached. Had hoped to have the program ask Detach Reference Files and I could say Y or N
What you are trying to do is actually quite simple (it must be as its the 1st time I've written anything in MS VBA since 2017!)
Copy the attached MVBA file into a directory which MS_VBAAUTOLOADPROJECTS is configured to search.
If you already have an MVBA which is using DesignFile Events, you can easily extract the relevant line from the OnDesignFileClosed event and the new procedure below it.
You will only see a prompt if there are reference files attached to the active model; you did not specify if your DGN files are multi-model therefore the code currently only operates on the active model. It should easy enough to modify the code to detach references in all models or specific to a model type.
5857.RP_Detach_Refs.mvba
PS I'm not sure why the upload added a numerical prefix to the file name
Special big thank you I finally figured out how to get Autorun.mvba to go out and run you file It always ask's now when closing a .dgn I commented out the one in
autorun and have yours loading must be running because when I close the files if they have a reference it asks
I so appreciate the help.
This super file you shared will it do something when opening a .dgn also? If so perhaps I could use this instead of the Autorun.mvba because the only thing I added to it was the lines Jon Summers was kind enough to provide. I have never done anything in VBA except macros. So forgive me if I get confused on the bigger programs like the Autorun and the one you gave me. I thought I could save loading an extra file. this is how I am getting it to work now making all three auto-load
'------------------------------------------------------------ 'OnDesignFileOpened(ByVal DesignFileName As String) ' This method will be called each time a design file is opened. ' The DesignFileName is the name of the file that was just opened, ' this is useful if you perform some sort of filtering based on file ' name or extension. Private Sub m_OpenCloseHooks_OnDesignFileOpened(ByVal DesignFileName As String) ' 011819 - Added Key-in command ' Place code you wish to execute each time a file is opened here. ' You could do all sorts of things here, but use caution as this is run ' for every file you open as long as this class is active. ' For this example, we will close all views except for View 1 ' and perform a Fit All. We will also use familiar MBE style commands ' for those trying to transition from MBE. '[A] - Personal Section Added Commands 'CadInputQueue.SendCommand "View Off All" 'Turn off all views 'CadInputQueue.SendCommand "View On 1" 'Turn View 1 on 'CadInputQueue.SendCommand "Window Tile" 'Resize View 1 to fit screen 'CadInputQueue.SendCommand "Fit All" 'Start Fit All command 'CadInputQueue.SendCommand "Selview 1" 'Apply to View 1 ' 011619 - The VBA RUN ViewAttributON also runs the AttribOFF section subroutine '{Note} Changing to comment for testing 'CadInputQueue.SendKeyin "vba run ViewAttribON" ' Turns on Attributes Off Attributes and Runs AA= & As= settings ' {Note} Changing to comment for testing '[B] - 052619 Modified Colors are messing up ________________________________________________________ RJB Dim KeyIn As String '[AA] 052219 - Runs macro in Module6 Set Settings Design File Preferences KeyIn = "VBA RUN [Default]Module6.SetSDFpreferences" ' 051319 - Testing adding a dim command" CadInputQueue.SendKeyin KeyIn ' RemoveModalDialogEventsHandler modalHandler ' As stated before, you can perform all kinds of things here. End Sub
Jon, thank you for the tip. I plan on going there ASAP . I have also asked a level 1 company programmer for some help. He is not a Micro-Station user but has given many tips on the older bat files and He does some VBA so I am hoping I can gather enough information.
Barry Lothian gave me a great routine that works for the Detach all. It is really great to get the help and the tips which help. You and Jan have been so valuable. Thanks again