changing sheet format
changing sheet format
(OP)
I know this topic has been discussed before. I checked previous threads but I couldn't find a clear answer.
I have about 100 drws where I need to change the sheet format. I wrote a macro that does that but in the end the drw does not get updated automatically. What else should I add at the end to achieve that. My macro ends like this:
ret2 = swPart.SetupSheet4(sSheetName, ret1(0), ret1(1), ret1(2), ret1(3), ret1(4), sNewTemplate, ret1(5), ret1(6), sViewName)
swPart.EditSketch
swPart.EditRebuild3
I have about 100 drws where I need to change the sheet format. I wrote a macro that does that but in the end the drw does not get updated automatically. What else should I add at the end to achieve that. My macro ends like this:
ret2 = swPart.SetupSheet4(sSheetName, ret1(0), ret1(1), ret1(2), ret1(3), ret1(4), sNewTemplate, ret1(5), ret1(6), sViewName)
swPart.EditSketch
swPart.EditRebuild3






RE: changing sheet format
Make sure your return value ret2 is explicitly defined as a Boolean with a Dim statement.
I've noticed sometimes SW API calls that have boolean return values do not function with a variant as a return variable.
RE: changing sheet format
RE: changing sheet format
dim ret2 as Boolean
dim sSheetName as string
dim sNewTemplate as string
dim sViewName as string
dim ret1 as variant
'......
ret2 = swPart.SetupSheet4(sSheetName, CLng(ret1(0)), CLng(ret1(1)), CDbl(ret1(2)), CDbl(ret1(3)), cbool(ret1(4)), sNewTemplate, CDbl(ret1(5)), CDbl(ret1(6)), sViewName)
Conventional VB wisdom is to at least place the variant values inside parentheses to force them to be evaluated as expressions, i.e. (ret1(1))
RE: changing sheet format
RE: changing sheet format
I agree with the "VB wisdom" and I did the change but that still didn't solve my problem.
Is there any way to "simulate" Reload sheet format in VB or VBA?
RE: changing sheet format
RE: changing sheet format
http://www.solidmag.com/Summary/sum_khJF03.htm
RE: changing sheet format
Dim swApp As SldWorks.SldWorks
Dim dMod As SldWorks.ModelDoc2
Dim dDwg As SldWorks.DrawingDoc
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long
Dim ret2 As Boolean
Dim ret1 As Variant
Dim NewTemplate As String
Dim ViewName As String
Dim actSheet As SldWorks.Sheet
Dim SheetName As String
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set actSheet = Part.GetCurrentSheet
SheetName = actSheet.GetName
ViewName = actSheet.CustomPropertyView
ret1 = actSheet.GetProperties
NewTemplate = "J:\DOCUMENT\TITLEBLK\solidworks\tb-part-C.slddrt"
'Stop
retval = Part.SetupSheet4(SheetName, (ret1(0)), swDwgTemplateCustom, (ret1(2)), (ret1(3)), (ret1(4)), NewTemplate, (ret1(5)), (ret1(6)), ViewName)
'retval = DrawingDoc.SetupSheet4 ( name, paperSize=0, templateIn, scale1=2, scale2=3, firstAngle=4, templateName, width=5, height=6, propertyViewName )
' = indicates ret1 array position as returned by sheet.getproperties
'use swDwgTemplateCustom
End Sub
RE: changing sheet format
are you saying that the piece of code above changes AND RELOADS the sheet format?
RE: changing sheet format
One thing I did differently was to use the enumerator swDwgTemplateCustom instead of the value in ret1(1) from the current sheet. Be sure to load your swConst.bas file module
RE: changing sheet format
Actually the prolems was this line:
' Sheet.SetTemplateName (sNewTemplate)
It was before:
ret2 = swPart.SetupSheet4(sSheetName, CLng(ret1(0)), CLng(ret1(1)), CDbl(ret1(2)), _
CDbl(ret1(3)), CBool(ret1(4)), sNewTemplate, CDbl(ret1(5)), CDbl(ret1(6)), sViewName)
After commenting it the macro worked and the drawings updated as expected.
Thanks for your help, Tick