Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing sheet format 1

Status
Not open for further replies.

dogarila

Mechanical
Oct 28, 2001
594
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

 
Replies continue below

Recommended for you

One possibility:
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.

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
All the variables including ret2 are explicitly dimensioned as what they are. The only variant is ret1.

 
Along the same lines, use CStr, CDbl, CLng, etc. keywords for any variants in your arguments.


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

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
No, I didn't type that fast. I was already typing this when you posted your reply.
[roll2]

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
Tick,

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?
 
Well, I'm out of semi-obvious answers. I am actually diggin into this a little.
 
'This worked
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
 
Tick,

are you saying that the piece of code above changes AND RELOADS the sheet format?
 
Yes. When it is done, my drawing is fully rebuilt and displaying the sheet format specified by the string NewTemplate.

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
 
I know about swDwgTemplateCustom. My drawings are all set like that so ret1(1) is always correct.

Actually the prolems was this line:

Code:
'        Sheet.SetTemplateName (sNewTemplate)
It was before:

Code:
        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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor