Hello all,
My name Stanislav Spektor from Israel.
I am use software version 2010 SP1.0.
Before few year one employee build macro file, in this macro has two parameters.
First parameter width, other parameter height in construction model.
After run macro, model change in two parameters, but problem, drawing sheet doesn’t change scale.
In this reason model exceed from drawing sheet.
I search helps who know macro and help me or give direction.
Macro code:
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("DetailItem145@DV1", "NOTE", 0.2043458840282, 0.1700934820286, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("DetailItem145@DV1", "NOTE", 0.2057870681322, 0.1700934820286, 0, False, 0, Nothing, 0)
boolstatus = Part.SetupSheet5("KOROT", 12, 12, 1, 2, False, "C:\\Program Files\\SolidWorks\\data\\A4-Vert.slddrt", 0.2794, 0.2159, "Default", False)
- Part.ClearSelection2 True
' Release Data
F = Part.DeleteCustomInfo2("", "makat")
F = Part.DeleteCustomInfo2("", "gimur")
Dim swView As SldWorks.View
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
For k = 6 To 15 '7-15 ''MIS110 6-15
W = k * 100
For j = 70 To 100 Step 5 '30-100
L = j * 100
swView.ReferencedConfiguration = Trim(Str(L)) & "-" & Trim(Str(W))
swModel.EditRebuild
For i = 1 To 5 ' GIMUR
'130 for B , 120 for A , 110 MISG110
gimur = 100 + i ' 01 - painted , 02 - megulvan, 04 - gilvun ham, 05 - meorav
g = Switch(i = 1, "öáåò", i = 2, "îâåìååï", i = 3, "ììà âéîåø", i = 4, "âéìååï çí", i = 5, "îòåøá")
' Prepare the MAKAT
makat = "09-" & Trim(Str(gimur + panel)) & "-00" & Trim(Str(W / 10)) & "-0" & Trim(Str(L / 10))
If W > 999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-0" & Trim(Str(W / 10)) & "-0" & Trim(Str(L / 10))
End If
If L > 9999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-00" & Trim(Str(W / 10)) & "-" & Trim(Str(L / 10))
End If
If W > 999 And L > 9999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-0" & Trim(Str(W / 10)) & "-" & Trim(Str(L / 10))
End If
' Capture Data
retval = Part.AddCustomInfo3("", "makat", swCustomInfoText, makat)
retval = Part.AddCustomInfo3("", "gimur", swCustomInfoText, g)
' Save
Part.SaveAs2 "C:\\NEWPDF1\\" & makat & ".PDF", 0, True, False
' Release Data
F = Part.DeleteCustomInfo2("", "makat")
F = Part.DeleteCustomInfo2("", "gimur")
Next i
Next j
Next k
End Sub
Thanks
Stanislav
SolidworksApi macros
Stanislav,
Welcome to the forums.
There are two ways you can fix this problem. You can either change the view's scale or the sheet's scale. To change the view's scale, use the API call IView::ScaleDecimal. To change the sheet's scale, use IDrawingDoc::SetupSheet5. "IDrawingDoc" refers to the interface and "SetupSheet5" refers to the interface member, by the way. API calls, interface members, methods, and functions are basically synonymous.
At the end of your code, but before End Sub, try putting this:
boolstatus = Part.SetupSheet5("KOROT", 12, 12,, , False, "C:\Program Files\SolidWorks\data\A4-Vert.slddrt", 0.2794, 0.2159, "Default", False)
However, replace and with the appropriate values so that your model is completely within the sheet.
I hope this helps.
Keith
Video Tutorials for the SolidWorks API
Hello Keith,
Thanks you for answer.
I checking is this.
Stanislav
Hello Keith,
I did is this, but is not help.
I not undestand something, i put only this code before End Sub or i must add code: for and if ?
I read helps ScaleDecimal and IDrawingDoc, if i undestand clear, must add Syntax.
Thanks
Stanislav
Stanislav,
I recommend that you watch some of our video tutorials so you can understand basic programming. Below I have placed the code in black that I believe you need. In red are the numerator and the denominator.
========
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("DetailItem145@Drawing View1", "NOTE", 0.2043458840282, 0.1700934820286, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("DetailItem145@Drawing View1", "NOTE", 0.2057870681322, 0.1700934820286, 0, False, 0, Nothing, 0)
boolstatus = Part.SetupSheet5("KOROT", 12, 12, 1, 2, False, "C:\Program Files\SolidWorks\data\A4-Vert.slddrt", 0.2794, 0.2159, "Default", False)
' Release Data
F = Part.DeleteCustomInfo2("", "makat")
F = Part.DeleteCustomInfo2("", "gimur")
Dim swView As SldWorks.View
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
' Set swView = swView.GetNextView
For k = 6 To 15 '7-15 ''MIS110 6-15
W = k * 100
For j = 70 To 100 Step 5 '30-100
L = j * 100
swView.ReferencedConfiguration = Trim(Str(L)) & "-" & Trim(Str(W))
swModel.EditRebuild
For i = 1 To 5 ' GIMUR
'130 for B , 120 for A , 110 MISG110
gimur = 100 + i ' 01 - painted , 02 - megulvan, 04 - gilvun ham, 05 - meorav
g = Switch(i = 1, "öáåò", i = 2, "îâåìååï", i = 3, "ììà âéîåø", i = 4, "âéìååï çí", i = 5, "îòåøá")
' Prepare the MAKAT
makat = "09-" & Trim(Str(gimur + panel)) & "-00" & Trim(Str(W / 10)) & "-0" & Trim(Str(L / 10))
If W > 999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-0" & Trim(Str(W / 10)) & "-0" & Trim(Str(L / 10))
End If
If L > 9999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-00" & Trim(Str(W / 10)) & "-" & Trim(Str(L / 10))
End If
If W > 999 And L > 9999 Then
makat = "09-" & Trim(Str(gimur + panel)) & "-0" & Trim(Str(W / 10)) & "-" & Trim(Str(L / 10))
End If
' Capture Data
retval = Part.AddCustomInfo3("", "makat", swCustomInfoText, makat)
retval = Part.AddCustomInfo3("", "gimur", swCustomInfoText, g)
' Save
Part.SaveAs2 "C:\NEWPDF1\" & makat & ".PDF", 0, True, False
' Release Data
F = Part.DeleteCustomInfo2("", "makat")
F = Part.DeleteCustomInfo2("", "gimur")
Next i
Next j
Next k
boolstatus = Part.SetupSheet5("KOROT", 12, 12, 1, 4, False, "C:\Program Files\SolidWorks\data\A4-Vert.slddrt", 0.2794, 0.2159, "Default", False)
End Sub
========
Keith
Video Tutorials for the SolidWorks API
Hello Keith,
Thanks proposal wath video tutorial.
I chechked your option, doesn't work properly .
Model still exceed from drawing sheet
Only change - drawing sheet , change scale to small and this reason blank in drawing.
I add picture.
Thanks
Stanislav