You can forcerebuild before calling the function
Thank you Christian
I tried this, but it's doesn't either run or rebuild the view before the macro runs.
Function swmRebuild(app As Variant, model As Variant, feat As Variant) As Variant Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc swModel.ForceRebuild3 False swModel.GraphicsRedraw2 swApp.RunMacro2 strMacroPath, strModuleName, strProcedureName, options, errors End Function
What you need isn't a macrofeature, you need an addin that does the work and has register to this
Is solidworks overwriting hole callouts or dimensions that your macrofeature overwrites?
(I ask because this plagues me every minute of every day)
If not, why does it have to run post rebuild?
Are you in the building, looking over my shoulder? Yes sir. That's exactly what is happening. Is the fix to use an add-in?
ok buddy are you ready for a nightmare?
if so let me know. its got to be the most annoying thing you will ever do.
it requires either an addin or a macro that is ran during solidworks launching.
see Keith Rice website CADSharp link here
in this link he shows how to start solidworks in a macro. see TARGET
you will need to have your macro register to
This is where the Hole callouts get set up
call you code to set all display dimensions
VERY IMPORTANT. Do not Use <MOD-DIAM> or <MOD-DEPTH> in your hole callouts. you will see why in a bit
here you look for anywhere solidworks added <MOD-DIAM> or <MOD-DEPTH> to your hole callouts.
these callouts need to be rewritten.
sometimes you will have to use SwModel.EditDimensionProperties3 for the DANG thing to accept your callout.
i had to write a massive infrastructure to accomplish this task. hole callouts are not fun to mess with with the API. solidworks thinks they know better than we do.
possibly use IAnnotations instead but they will not auto attach to the edge of the hole always pointing at the center . they just attach to a stupid point and look dumb when moved.
You should be looking at this:
DDrawingDocEvents_RegenPostNotifyEventHandler Delegate (SolidWorks.Interop.sldworks) Post-notifies the user program when a drawing document has been regenerated.
You can also use IModelDoc2::GetUpdateStamp to determine when changes have taken place in this document.
beat ya to it hehehe
silly talk sir. my internet connection is just a little faster than yours
With all of your thoughts, here's is how I worked it out.
I changed the "swmRebuild" to create a instance of an event handler class.
Function swmRebuild(varApp As Variant, varDoc As Variant, varFeat As Variant) As Variant Dim App As SldWorks.SldWorks Dim Doc As SldWorks.ModelDoc2 Dim feat As SldWorks.Feature Dim FeatData As SldWorks.MacroFeatureData Set App = varApp Set Doc = varDoc Set feat = varFeat Set evHdlr = New clsEventHandler End Function
I created an event handler class that runs the macro "after" the rebuild completed. This is the entire class. It ain't perfect, but it works well.
Option Explicit Dim swApp As SldWorks.SldWorks Dim WithEvents swDraw As SldWorks.DrawingDoc Dim options As Long Dim errors As Long Const strMacroPath As String = "S:\Macros\RunThisMacro.swp" Const strModuleName As String = "modStartHere" Const strProcedureName As String = "main" Private Sub Class_Initialize() On Error Resume Next Set swApp = Application.SldWorks Set swDraw = swApp.ActiveDoc End Sub Private Function swDraw_RegenPostNotify() As Long swApp.RunMacro2 strMacroPath, strModuleName, strProcedureName, options, errors End Function
Hold on there buddy. every time it rebuilds its going to create that class and events will be fired for how ever many times they have rebuilt.
To make sure this doesnt happen, suppress that feature on the First call to regenpostnotify.
if you must go this route do this below are BOLD items that you should make sure you add.
i am not sure if setting SwDraw = nothing will kill all events associated with it,
i believe you will need to use the dropdown to register for the DestroyNotify event
if you don't do that i think its going to probably crash.
- Dim swApp As SldWorks.SldWorks
- Dim WithEvents swDraw As SldWorks.DrawingDoc
- Dim options As Long
- Dim errors As Long
- Const strMacroPath As String = "S:\Macros\RunThisMacro.swp"
- Const strModuleName As String = "modStartHere"
- Const strProcedureName As String = "main"
- Dim CallingMacroFeature as feature
- Dim IsFirstRegenPostNotify as boolean
- Private Sub Class_Initialize(Byval MacroFeat as feature)
- On Error Resume Next
- Set swApp = Application.SldWorks
- Set swDraw = swApp.ActiveDoc
- callingMacrofeature = macrofeat
- IsFirstRegenPostNotify = true
- End Sub
- private function SwDraw_DestroNotify as integer
- swdraw = nothing
- end function
- Private Function swDraw_RegenPostNotify() As Long
- if isfirstRegenPostNotify then
- CallingMacroFeature.SetSuppression swfeaturesuppressionAction_e.SwSuppressFeature,swinconfigOpts_e.SwThisConfiguration
- IsFirstRegenPostNotify = False
- end if
- swApp.RunMacro2 strMacroPath, strModuleName, strProcedureName, options, errors
- End Function
also just so you know. your problem is not fixed yet. create a multi document sheet and save it as a multiple drawing pdf.
lots of times the callouts will revert themselves back to what Solidworks and their infinite wisdom think they should be.
i have to register to IModelView:GraphicsRenderPostNotify also and check for places where <MOD-DIAM> exist or <MOD-DEPTH>.
yeah it checks every dang time that the screen is redrawn. its so annoying.
if you dont have this problem then that is great. all it takes is one non circular edge that is part of the hole that is being called out to cause a revert to the original solidworks garbage.
in their defense they are trying to call it out based on the geometry of the targeted feature.
I updated the macro feature to set the events class to nothing after it fires the "RunMacro2" statement. Now there will not be orphan instances in the Windows universe...