• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

drawing scale setting via macro moves the odds

  • Thread starter Thread starter iovem
  • Start date Start date

iovem

Guest
Bye to all,
I have a couple of macros that allow me to change the scale of a drawing with a button. a macro increases the scale, the other decreases it.

I noticed that at the change of scale, the spacing of quotas changes. happens only on the basic view and does not happen if the change of the scale takes place through the solidworks interface. I initially thought it was due to the subject [I]scaleannoposition[/I] method setscale , but also setting true I get the same result.

Moreover, in another macro, use setupsheet5 to change the sheet size and also in this case passing as arguments the scale factor, the size move.

Thank you in advance who can help me.

attached you will find an example file and a short video where I follow the macro and on the basic view the spacing of the quota changes.

Here are the codes
Code:
dim swapp as sldworks.sldworks
dim swdraw as sldworks.idrawingdoc
dim swsheet as sldworks.sheet
dim sheetproperties as variant
dim scalanum as double
dim scaladen as double
dim scaleannoposition as boolean
dim scaleannotextheight as boolean
dim value as boolean

sub main()

    set swapp = application.sldworks
    dim swdraw                  as sldworks.idrawingdoc
    dim swsheet                 as sldworks.sheet
    
    dim swmodel as sldworks.modeldoc2
    set swmodel = swapp.activedoc
    
    if swmodel is nothing then
        msgbox ("open a drawing")
        goto finally_
    end if
    
    if swmodel.getpathname() = "" then
        msgbox ("save the file")
        goto finally_
    end if
    
    if not swmodel.gettype() = swdocdrawing then
        msgbox ("open a drawing")
        goto finally_
    end if
    
    set swdraw = swapp.activedoc
    set swsheet = swdraw.getcurrentsheet
    
    sheetproperties = swsheet.getproperties2
    scalanum = sheetproperties(2)
    scaladen = sheetproperties(3)
    
    if scalanum = 1 then
        select case scaladen
            case is = 1
                scaladen = 1
                scalanum = 2
            case is = 2
                scaladen = 1
            case is = 2.5
                scaladen = 2
            case is = 4
                scaladen = 2.5
            case is = 5
                scaladen = 4
            case is = 7.5
                scaladen = 5
            case is = 10
                scaladen = 7.5
            case is = 15
                scaladen = 10
            case is = 20
                scaladen = 15
            case is = 25
                scaladen = 20
            case is = 30
                scaladen = 25
            case is = 50
                scaladen = 30
            case is = 75
                scaladen = 50
            case is = 100
                scaladen = 75
            case is = 150
                scaladen = 100
            case is = 200
                scaladen = 150
            case is = 250
                scaladen = 200
            case else
                msgbox "scale not found", vbexclamation
                goto finally_
            end select
    elseif scaladen = 1 then
        select case scalanum
            case is = 2
             scalanum = 2.5
            case is = 2.5
             scalanum = 4
            case is = 4
             scalanum = 5
        case else
                msgbox "scale not found", vbexclamation
                goto finally_
        end select
    end if
    
    scaleannoposition = false
    scaleannotextheight = false
    value = swsheet.setscale(scalanum, scaladen, scaleannoposition, scaleannotextheight)
    
finally_:
        
end sub

e
Code:
dim swapp as sldworks.sldworks
dim swdraw as sldworks.idrawingdoc
dim swsheet as sldworks.sheet
dim sheetproperties as variant
dim scalanum as double
dim scaladen as double
dim scaleannoposition as boolean
dim scaleannotextheight as boolean
dim value as boolean

sub main()

    set swapp = application.sldworks
    dim swdraw                  as sldworks.idrawingdoc
    dim swsheet                 as sldworks.sheet
    
    dim swmodel as sldworks.modeldoc2
    set swmodel = swapp.activedoc
    
    if swmodel is nothing then
        msgbox ("open a drawing")
        goto finally_
    end if
    
    if swmodel.getpathname() = "" then
        msgbox ("save the file")
        goto finally_
    end if
    
    if not swmodel.gettype() = swdocdrawing then
        msgbox ("open a drawing")
        goto finally_
    end if
    
    set swdraw = swapp.activedoc
    set swsheet = swdraw.getcurrentsheet
    
    sheetproperties = swsheet.getproperties2
    scalanum = sheetproperties(2)
    scaladen = sheetproperties(3)
    
    if scalanum = 1 then
        select case scaladen
            case is = 1
                scaladen = 2
            case is = 2
                scaladen = 2.5
            case is = 2.5
                scaladen = 4
            case is = 4
                scaladen = 5
            case is = 5
                scaladen = 7.5
            case is = 7.5
                scaladen = 10
            case is = 10
                scaladen = 15
            case is = 15
                scaladen = 20
            case is = 20
                scaladen = 25
            case is = 25
                scaladen = 30
            case is = 30
                scaladen = 50
            case is = 50
                scaladen = 75
            case is = 75
                scaladen = 100
            case is = 100
                scaladen = 150
            case is = 150
                scaladen = 200
            case is = 200
                scaladen = 250                
            case else
                msgbox "scale not found" , vbexclamation
                goto finally_
            end select
    elseif scaladen = 1 then
        select case scalanum
            case is = 1
                scalanum = 1
                scaladen = 2
            case is = 2
                scalanum = 1
            case is = 2.5
                scalanum = 2
            case is = 4
                scalanum = 2.5
            case is = 5
                scalanum = 4
        case else
                msgbox "scale not found" , vbexclamation
                goto finally_
        end select
    end if
    
    scaleannoposition = false
    scaleannotextheight = false
    value = swsheet.setscale(scalanum, scaladen, scaleannoposition, scaleannotextheight)
    
finally_:
        
end sub[ICODE]
 

Attachments

I think I found a solution, or at least a "tampone." the problem seems to be related to the use of sheet::setscale and sheet::reloadtemplate. now, instead of setscale use setupsheet5 to set the scale of the sheet and instead of reloading the format with reloadedmplates, first imposed an empty format and then loaded the definitive one. It's a little bit of a "accrocchio", but it works for me and I couldn't do better.

I found a series of sprs related to the topic: spr 206559 and 409201

I attach the code that works for me hoping it can be useful to someone else.
 

Attachments

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top