Hope in the new year, let my solidowrks API skills to a higher level.
Must be familiar key Syntax
1 GetFirstDisplayDimension + GetDimension + GetAnnotation + GetPosition Syntax
function code
Function NoDelDimension(SwDraw As DrawingDoc, SwView As View, NoDelDim)
tmp = SwDraw.Extension.SelectByID2(ViewName, "DRAWINGVIEW", 0#, 0#, 0, True, 0, Nothing, 0)
Annotations = SwDraw.InsertModelAnnotations3(0, 1736728, False, True, True, True) ''
For ii = 0 To UBound(Annotations) ''
Set SwAnn = Annotations(ii)
Set SwDispDim = SwAnn.GetSpecificAnnotation
Set SwDim = SwDispDim.GetDimension
Next ii
For ii = 0 To UBound(Annotations)
Set SwAnn = Annotations(ii)
If UCase(SwAnn.GetName) Like "*DN*" Or UCase(SwAnn.GetName) Like "*THK*" Then
SwAnn.Select True
End If
Next ii
End Function
Function BreakOut(SwDraw As DrawingDoc, SwView As View)
Dim Ww, Hh
SwDraw.ActivateView SwView.Name
SwDraw.ForceRebuild3 True
Var = SwView.GetOutline
For ii = 0 To 3
Var(ii) = Var(ii) / SwView.ScaleDecimal
Next ii
Ww = Var(2) - Var(0)
Hh = Var(3) - Var(1)
''
With SwDraw
.SketchRectangle -Ww / 2, -Hh / 2, 0, Ww / 2, Hh / 2, 0, True
.CreateBreakOutSection Depth / 1000
End With
End Function
2 InsertFamilyTableNew + GetOLEObjects(Vv) +
''
Function RngInsertDesign(SwModel As ModelDoc2, Xls As Excel.Application, _
ConfRng As Range, ConfHeadRng, ConfTabRng, MassRng As Range, retuDimRng As Range, _
CutPlateCustInfoRng As Range, CutDimRng As Range)
SwModel.InsertFamilyTableNew
Dim SwOleObj As SwOLEObject, vOle, Vv As Long
vOle = SwModel.Extension.GetOLEObjects(Vv)
Set SwOleObj = vOle(UBound(vOle))
Set Wk = SwOleObj.SetActive(True)
ConfHeadRng.Copy
With Wk.Sheets(1).Range("B2")
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
End With
''
SwOleObj.SetActive False
Set SwDesgTab = SwModel.GetDesignTable
SwDesgTab.Attach
SwModel.CloseFamilyTable
''
For ii = 1 To ConfRng.Rows.Count
With SwModel
Str = "@@" & ConfRng(ii, 1) & "@" & .GetTitle & """"
.AddCustomInfo3 ConfRng(ii, 1), "质量", 30, """SW-Mass" & Str
'.AddCustomInfo3 ConfRng(ii, 1), "下料质量", 30, "/"
.CustomInfo2(ConfRng(ii, 1), "质量") = """SW-Mass" & Str
.AddCustomInfo3 ConfRng(ii, 1), "材料", 30, """SW-Material" & Str
If UCase(.GetTitle) Like "*SLDASM*" Then
.CustomInfo2(ConfRng(ii, 1), "材料") = "组合件"
Set SwAssy = SwModel
CompArr = SwAssy.GetComponents(True)
SumVolMass SwModel, CompArr, ConfRng(ii, 1)
Else
.CustomInfo2(ConfRng(ii, 1), "材料") = """SW-Material" & Str
End If
.ForceRebuild3 False
End With
End Function
3 InsertBomTable2 + ReferencedConfiguration + SwBomFeat.SetConfigurations
Function A3InsertBom(SwView As View, xx, yy, BOMPath)
Dim AnchorType, BomType
AnchorType = SwConst.swBOMConfigurationAnchor_BottomRight
BomType = SwConst.swBomType_e.swBomType_TopLevelOnly
Configuration = ""
Set swBomAnn = SwView.InsertBomTable2(False, xx / 1000, yy / 1000, AnchorType, BomType, Configuration, BOMPath)
''
Dim SwBomFeat As BomFeature, Names, Visible
Set SwBomFeat = swBomAnn.BomFeature
Names = SwBomFeat.GetConfigurations(False, Visible)
For jj = 0 To UBound(Names)
If Names(jj) = SwView.ReferencedConfiguration Then
Visible(jj) = True
Exit For
End If
Next jj
boolstatus = SwBomFeat.SetConfigurations(False, Visible, Names)
End Function
SolidworksApi macros