×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

changing sheet format

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

RE: changing sheet format

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.

All this machinery making modern music can still be open-hearted.

RE: changing sheet format

(OP)
All the variables including ret2 are explicitly dimensioned as what they are. The only variant is ret1.

RE: changing sheet format

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

All this machinery making modern music can still be open-hearted.

RE: changing sheet format

No, I didn't type that fast.  I was already typing this when you posted your reply.

All this machinery making modern music can still be open-hearted.

RE: changing sheet format

(OP)
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?

RE: changing sheet format

Well, I'm out of semi-obvious answers.  I am actually diggin into this a little.

RE: changing sheet format

'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

RE: changing sheet format

(OP)
Tick,

are you saying that the piece of code above changes AND RELOADS the sheet format?

RE: changing 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

RE: changing sheet format

(OP)
I know about swDwgTemplateCustom. My drawings are all set like that so ret1(1) is always correct.

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources