Open de toolkit ↗
← Alle tools
SolidWorks · Inventor

Macro-bibliotheek

Kopieerbare VBA-macro's: STEP-export, batch opslaan, eigenschappen tonen.

DIRECT BEREKEND · FORMULE & AANNAMES IN BEELD

Voorbeeldcode

Macro-bibliotheek

VBA-macro's voor SolidWorks (SldWorks API): STEP-export, alles opslaan en custom properties tonen. De code hieronder is exact de inhoud van het downloadbare .bas-bestand — geen aparte, mogelijk afwijkende kopie. Test macro's altijd eerst op een kopie van je bestanden — API-methodesignatuur kan licht verschillen per SolidWorks-versie. Inventor gebruikt een ander objectmodel (iLogic / Inventor API via VB.NET) — zie de aanvullende macro's voor Inventor-voorbeelden.

STEP-export

Slaat het actieve document op als STEP (.step), naast het bronbestand. Controleert eerst of het document al een bestandspad heeft.

Download .bas
Attribute VB_Name = "ExportActiefNaarSTEP"
'
' SolidWorks 2024 VBA-macro — Exporteer actief document naar STEP
' https://www.mechify.nl/cad/macros
'
' Wat: slaat het actieve part of assembly op als .step, naast het
' bestaande bestand, met dezelfde naam.
' Vereist: het document is al minstens één keer opgeslagen (heeft een pad).
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    If swModel.GetType <> swDocPART And swModel.GetType <> swDocASSEMBLY Then
        MsgBox "Deze macro is alleen bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If

    Dim docPath As String
    docPath = swModel.GetPathName

    If docPath = "" Then
        MsgBox "Sla het document eerst één keer op (nog geen bestandspad).", vbExclamation
        Exit Sub
    End If

    If InStrRev(docPath, ".") = 0 Then
        MsgBox "Bestandspad heeft geen extensie.", vbExclamation
        Exit Sub
    End If

    Dim stepPath As String
    stepPath = Left(docPath, InStrRev(docPath, ".")) & "step"

    Dim saveErrors As Long
    Dim saveWarnings As Long

    Dim ok As Boolean
    ' swSaveAsOptions_Copy: exporteer een kopie zonder het open document aan
    ' het nieuwe bestand te koppelen. Zonder deze vlag kan SolidWorks het
    ' geopende document laten verwijzen naar het geëxporteerde bestand.
    ok = swModel.Extension.SaveAs(stepPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent Or swSaveAsOptions_Copy, Nothing, saveErrors, saveWarnings)

    If ok And saveErrors = 0 Then
        MsgBox "Opgeslagen als:" & vbCrLf & stepPath, vbInformation
    Else
        MsgBox "Exporteren mislukt (foutcode " & saveErrors & ").", vbCritical
    End If

End Sub

Alles opslaan

Loopt door alle geopende documenten en slaat elk document met niet-opgeslagen wijzigingen op. Rapporteert hoeveel zijn opgeslagen en hoeveel overgeslagen (geen wijzigingen, of nog geen bestandspad).

Download .bas
Attribute VB_Name = "SlaAllesOp"
'
' SolidWorks 2024 VBA-macro — Sla alle gewijzigde open documenten op
' https://www.mechify.nl/cad/macros
'
' Wat: loopt door alle op dit moment geopende documenten en slaat elk
' document met niet-opgeslagen wijzigingen op. Documenten zonder
' wijzigingen, of die nog geen bestandspad hebben, worden overgeslagen.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks

    Dim swDoc As SldWorks.ModelDoc2
    Set swDoc = swApp.GetFirstDocument

    Dim saved As Integer
    Dim skipped As Integer
    saved = 0
    skipped = 0

    Do While Not swDoc Is Nothing

        If swDoc.GetSaveFlag Then

            If swDoc.GetPathName = "" Then
                skipped = skipped + 1
            Else
                Dim saveErrors As Long
                Dim saveWarnings As Long
                Dim ok As Boolean
                ok = swDoc.Save3(swSaveAsOptions_Silent, saveErrors, saveWarnings)

                If ok And saveErrors = 0 Then
                    saved = saved + 1
                Else
                    skipped = skipped + 1
                End If
            End If

        Else
            skipped = skipped + 1
        End If

        Set swDoc = swDoc.GetNext

    Loop

    MsgBox saved & " document(en) opgeslagen." & vbCrLf & _
           skipped & " overgeslagen (geen wijzigingen, of nog niet opgeslagen).", vbInformation

End Sub

Eigenschappen tonen

Toont alle custom properties van het actieve document in een berichtvenster. Alleen-lezen, wijzigt niets.

Download .bas
Attribute VB_Name = "ToonCustomProperties"
'
' SolidWorks 2024 VBA-macro — Toon custom properties van het actieve document
' https://www.mechify.nl/cad/macros
'
' Wat: leest alle custom properties (configuratie-onafhankelijk, "") van
' het actieve document en toont ze in een berichtvenster. Alleen-lezen,
' wijzigt niets.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    Dim swCustProp As SldWorks.CustomPropertyManager
    Set swCustProp = swModel.Extension.CustomPropertyManager("")

    Dim propNames As Variant
    propNames = swCustProp.GetNames

    If IsEmpty(propNames) Then
        MsgBox "Geen custom properties gevonden.", vbInformation
        Exit Sub
    End If

    Dim msg As String
    Dim i As Long

    For i = 0 To UBound(propNames)
        Dim valOut As String
        Dim resolvedVal As String
        Dim wasResolved As Boolean
        swCustProp.Get5 propNames(i), False, valOut, resolvedVal, wasResolved
        msg = msg & propNames(i) & " = " & resolvedVal & vbCrLf
    Next i

    MsgBox msg, vbInformation, "Custom properties — " & swModel.GetTitle

End Sub

Downloadbare macro’s

VBA-modules en aanvullende rapportmacro’s voor SolidWorks en Inventor. Inspecteer de code en test op een kopie; Mechify voert deze bestanden niet uit.

14 downloadbare VBA-macro’s

Importeer .bas-bestanden via File > Import File in de VBA-editor. Bij handmatig plakken laat je de eerste regel Attribute VB_Name weg; die regel hoort bij het importformaat.

Wat ‘beoordeeld’ hier betekent

Handmatige bronreview plus geautomatiseerde statische controles op bestanddekking, scheiding van SolidWorks-/Inventor-identifiers en metadata. Geen compile- of runtimetest in CAD.

Een doelversie noemt de gebruikte API-documentatie; het is geen bewijs dat de macro in die CAD-versie draait. Test elke macro eerst op een kopie in jouw eigen CAD-installatie.

SolidWorks 2024

Installeren: Tools > Macro > New, plak de code in de module — of importeer het .bas-bestand direct via de VBA-editor (File > Import File).

Exporteer naar STEP

Slaat het actieve part of assembly op als .step, naast het bestaande bestand.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Alleen opgeslagen parts/assemblies; een bestaande STEP kan zonder bevestiging worden overschreven. Exportopties en referenties zijn niet in SolidWorks getest.

SOLIDWORKS API 2024 — SaveAs ↗

Download .bas

SHA-256: ba6572cf3d012446399bd361c6f2268f73cf1931edd2642fdb1bbec2b685fce8

Bekijk VBA-code voor Exporteer naar STEP
Attribute VB_Name = "ExportActiefNaarSTEP"
'
' SolidWorks 2024 VBA-macro — Exporteer actief document naar STEP
' https://www.mechify.nl/cad/macros
'
' Wat: slaat het actieve part of assembly op als .step, naast het
' bestaande bestand, met dezelfde naam.
' Vereist: het document is al minstens één keer opgeslagen (heeft een pad).
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    If swModel.GetType <> swDocPART And swModel.GetType <> swDocASSEMBLY Then
        MsgBox "Deze macro is alleen bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If

    Dim docPath As String
    docPath = swModel.GetPathName

    If docPath = "" Then
        MsgBox "Sla het document eerst één keer op (nog geen bestandspad).", vbExclamation
        Exit Sub
    End If

    If InStrRev(docPath, ".") = 0 Then
        MsgBox "Bestandspad heeft geen extensie.", vbExclamation
        Exit Sub
    End If

    Dim stepPath As String
    stepPath = Left(docPath, InStrRev(docPath, ".")) & "step"

    Dim saveErrors As Long
    Dim saveWarnings As Long

    Dim ok As Boolean
    ' swSaveAsOptions_Copy: exporteer een kopie zonder het open document aan
    ' het nieuwe bestand te koppelen. Zonder deze vlag kan SolidWorks het
    ' geopende document laten verwijzen naar het geëxporteerde bestand.
    ok = swModel.Extension.SaveAs(stepPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent Or swSaveAsOptions_Copy, Nothing, saveErrors, saveWarnings)

    If ok And saveErrors = 0 Then
        MsgBox "Opgeslagen als:" & vbCrLf & stepPath, vbInformation
    Else
        MsgBox "Exporteren mislukt (foutcode " & saveErrors & ").", vbCritical
    End If

End Sub

Batch-export tekeningen naar PDF

Exporteert elke geopende, al opgeslagen tekening naar PDF.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Alleen open, opgeslagen tekeningen; PDF-instellingen, fonts en referenties zijn niet in SolidWorks getest.

SOLIDWORKS API 2024 — SaveAs ↗

Download .bas

SHA-256: 57e6df2ec24663650da4834816daa9c164bc1aeeb062623c2944ef055ddf7dc3

Bekijk VBA-code voor Batch-export tekeningen naar PDF
Attribute VB_Name = "BatchExportTekeningenNaarPDF"
'
' SolidWorks 2024 VBA-macro — Batch-export open tekeningen naar PDF
' https://www.mechify.nl/cad/macros
'
' Wat: loopt door alle op dit moment geopende documenten, en exporteert
' elke tekening (.SLDDRW) die al een bestandspad heeft naar PDF, naast
' het bestaande bestand, met dezelfde naam.
' Parts en assemblies worden overgeslagen.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks

    Dim swDoc As SldWorks.ModelDoc2
    Set swDoc = swApp.GetFirstDocument

    Dim exported As Integer
    Dim skipped As Integer
    exported = 0
    skipped = 0

    Do While Not swDoc Is Nothing

        If swDoc.GetType = swDocDRAWING Then

            Dim docPath As String
            docPath = swDoc.GetPathName

            If docPath = "" Or InStrRev(docPath, ".") = 0 Then
                skipped = skipped + 1
            Else
                Dim pdfPath As String
                pdfPath = Left(docPath, InStrRev(docPath, ".")) & "pdf"

                Dim saveErrors As Long
                Dim saveWarnings As Long
                Dim ok As Boolean

                ' Eén beschadigd of vergrendeld document mag de rest van de
                ' batch niet afbreken — vang fouten per document af, net als
                ' de Inventor-twin.
                On Error Resume Next
                ok = swDoc.Extension.SaveAs(pdfPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, saveErrors, saveWarnings)
                If Err.Number <> 0 Then
                    ok = False
                    Err.Clear
                End If
                On Error GoTo 0

                If ok And saveErrors = 0 Then
                    exported = exported + 1
                Else
                    skipped = skipped + 1
                End If
            End If

        End If

        Set swDoc = swDoc.GetNext

    Loop

    MsgBox exported & " tekening(en) geëxporteerd naar PDF." & vbCrLf & _
           skipped & " overgeslagen (geen tekening, of nog niet opgeslagen).", vbInformation

End Sub

Toon custom properties

Leest de configuratie-onafhankelijke custom properties van het actieve document. Alleen-lezen.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Leest alleen documentniveau-eigenschappen, niet configuratiespecifieke waarden; niet in SolidWorks getest.

SOLIDWORKS API 2024 — CustomPropertyManager ↗

Download .bas

SHA-256: c4b33c0e8a133ac0fb63b8aca88b6428deb4c73b3dc725bed5344bbb32888416

Bekijk VBA-code voor Toon custom properties
Attribute VB_Name = "ToonCustomProperties"
'
' SolidWorks 2024 VBA-macro — Toon custom properties van het actieve document
' https://www.mechify.nl/cad/macros
'
' Wat: leest alle custom properties (configuratie-onafhankelijk, "") van
' het actieve document en toont ze in een berichtvenster. Alleen-lezen,
' wijzigt niets.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    Dim swCustProp As SldWorks.CustomPropertyManager
    Set swCustProp = swModel.Extension.CustomPropertyManager("")

    Dim propNames As Variant
    propNames = swCustProp.GetNames

    If IsEmpty(propNames) Then
        MsgBox "Geen custom properties gevonden.", vbInformation
        Exit Sub
    End If

    Dim msg As String
    Dim i As Long

    For i = 0 To UBound(propNames)
        Dim valOut As String
        Dim resolvedVal As String
        Dim wasResolved As Boolean
        swCustProp.Get5 propNames(i), False, valOut, resolvedVal, wasResolved
        msg = msg & propNames(i) & " = " & resolvedVal & vbCrLf
    Next i

    MsgBox msg, vbInformation, "Custom properties — " & swModel.GetTitle

End Sub

Sla alles op

Slaat elk geopend document met niet-opgeslagen wijzigingen op.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Slaat gewijzigde, reeds opgeslagen open documenten op; foutafhandeling en referentie-updates zijn niet in SolidWorks getest.

SOLIDWORKS API 2024 — GetSaveFlag ↗

Download .bas

SHA-256: 29e3603980f3c8fa9b9550de249f74476445159dcd9e60c5d1ff430a1f96cd33

Bekijk VBA-code voor Sla alles op
Attribute VB_Name = "SlaAllesOp"
'
' SolidWorks 2024 VBA-macro — Sla alle gewijzigde open documenten op
' https://www.mechify.nl/cad/macros
'
' Wat: loopt door alle op dit moment geopende documenten en slaat elk
' document met niet-opgeslagen wijzigingen op. Documenten zonder
' wijzigingen, of die nog geen bestandspad hebben, worden overgeslagen.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks

    Dim swDoc As SldWorks.ModelDoc2
    Set swDoc = swApp.GetFirstDocument

    Dim saved As Integer
    Dim skipped As Integer
    saved = 0
    skipped = 0

    Do While Not swDoc Is Nothing

        If swDoc.GetSaveFlag Then

            If swDoc.GetPathName = "" Then
                skipped = skipped + 1
            Else
                Dim saveErrors As Long
                Dim saveWarnings As Long
                Dim ok As Boolean
                ok = swDoc.Save3(swSaveAsOptions_Silent, saveErrors, saveWarnings)

                If ok And saveErrors = 0 Then
                    saved = saved + 1
                Else
                    skipped = skipped + 1
                End If
            End If

        Else
            skipped = skipped + 1
        End If

        Set swDoc = swDoc.GetNext

    Loop

    MsgBox saved & " document(en) opgeslagen." & vbCrLf & _
           skipped & " overgeslagen (geen wijzigingen, of nog niet opgeslagen).", vbInformation

End Sub

Exporteer vlak patroon naar DXF

Slaat het vlakke patroon van een plaatwerk-part op als .dxf.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Vereist een opgeslagen plaatwerk-part met Flat-Pattern-feature. De generieke SaveAs-route garandeert geen betrouwbaar vlak-patroonresultaat; inspecteer elke DXF. Niet in SolidWorks getest.

SOLIDWORKS API 2024 — SaveAs ↗

Download .bas

SHA-256: 7a229f39f5caa630ac2a914bf57a6461944ac9419e8db113c48a2b91e105c130

Bekijk VBA-code voor Exporteer vlak patroon naar DXF
Attribute VB_Name = "ExporteerVlakPatroonNaarDXF"
'
' SolidWorks 2024 VBA-macro — Exporteer vlak patroon naar DXF
' https://www.mechify.nl/cad/macros
'
' Wat: zoekt de Flat-Pattern-feature van het actieve plaatwerk-part,
' schakelt die tijdelijk in (unsuppress) als dat nodig is, slaat het
' vlakke patroon op als .dxf naast het bestaande bestand, en zet de
' feature daarna terug naar de oorspronkelijke staat.
' Vereist: het actieve document is een plaatwerk-part met een
' Flat-Pattern-feature, en is al minstens één keer opgeslagen.
' Zie ook de rekenhulp Richtlijnen kanten op deze site voor Ri,
' beenlengte en Z-buiging bij het plaatwerkontwerp zelf.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Tools > Macro > New, plak deze code in de module (of
' importeer dit .bas-bestand direct via VBA-editor > File > Import File).
'
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    If swModel.GetType <> swDocPART Then
        MsgBox "Geen part-document. Open een plaatwerk-part.", vbExclamation
        Exit Sub
    End If

    Dim docPath As String
    docPath = swModel.GetPathName

    If docPath = "" Then
        MsgBox "Sla het document eerst één keer op (nog geen bestandspad).", vbExclamation
        Exit Sub
    End If

    ' Zoek de Flat-Pattern-feature op type, niet op naam (naam kan
    ' afwijken door taal of hernoemen).
    Dim swFeat As SldWorks.Feature
    Set swFeat = swModel.FirstFeature

    Dim swFlatFeat As SldWorks.Feature
    Do While Not swFeat Is Nothing
        If swFeat.GetTypeName2 = "FlatPattern" Then
            Set swFlatFeat = swFeat
            Exit Do
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop

    If swFlatFeat Is Nothing Then
        MsgBox "Geen Flat-Pattern-feature gevonden. Is dit een plaatwerk-part?", vbExclamation
        Exit Sub
    End If

    Dim wasSuppressed As Boolean
    wasSuppressed = swFlatFeat.IsSuppressed

    If wasSuppressed Then
        swFlatFeat.SetSuppression2 swUnSuppressFeature, swThisConfiguration, Nothing
        ' Unsuppress alleen markeert de feature als te herbouwen; zonder een
        ' expliciete rebuild kan SaveAs de VORIGE (verouderde) geometrie
        ' exporteren. Forceer daarom een rebuild voordat we wegschrijven.
        swModel.EditRebuild3
    End If

    If InStrRev(docPath, ".") = 0 Then
        MsgBox "Bestandspad heeft geen extensie.", vbExclamation
        Exit Sub
    End If

    Dim dxfPath As String
    dxfPath = Left(docPath, InStrRev(docPath, ".")) & "dxf"

    Dim saveErrors As Long
    Dim saveWarnings As Long
    Dim ok As Boolean
    ' swSaveAsOptions_Copy: exporteer een kopie zonder het open document aan
    ' het nieuwe bestand te koppelen (zie ook export-step.bas).
    '
    ' LET OP — dit is SaveAs op het part-document zelf, niet de documenteerde
    ' ExportToDWG2-route (met bSelectedFeature op de Flat-Pattern-feature) of
    ' ExportFlatPatternView. Met de Flat-Pattern-feature unsuppressed
    ' exporteert SaveAs in de praktijk meestal het vlakke patroon, maar dat
    ' gedrag is per SolidWorks-versie en tekeningsjabloon niet gegarandeerd.
    ' Controleer het geëxporteerde bestand altijd zelf: open de DXF en
    ' bevestig dat je het UITGEVOUWEN vlakke patroon ziet (rechte omtrek +
    ' buiglijnen), niet een projectie van het gevouwen deel. Stuur nooit
    ' ongecontroleerd naar de laser.
    ok = swModel.Extension.SaveAs(dxfPath, swSaveAsCurrentVersion, swSaveAsOptions_Silent Or swSaveAsOptions_Copy, Nothing, saveErrors, saveWarnings)

    If wasSuppressed Then
        swFlatFeat.SetSuppression2 swSuppressFeature, swThisConfiguration, Nothing
    End If

    If ok And saveErrors = 0 Then
        MsgBox "Opgeslagen als:" & vbCrLf & dxfPath & vbCrLf & vbCrLf & _
            "Controleer de DXF vóór gebruik: dit moet het uitgevouwen vlakke " & _
            "patroon zijn, niet een projectie van het gevouwen deel.", vbInformation
    Else
        MsgBox "Exporteren mislukt (foutcode " & saveErrors & ").", vbCritical
    End If

End Sub

Massa en zwaartepunt

Rapporteert kg, mm³ en zwaartepunt in mm voor de actieve configuratie. Open een actueel part of opgeloste assembly met juiste materialen. Wist de selectie; slaat niets op. Start main.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Uitkomst hangt af van opgeloste geometrie, materiaal en actieve configuratie; eenheden/API-aanroepen zijn alleen statisch beoordeeld.

SOLIDWORKS API — CreateMassProperty ↗

Download .bas

SHA-256: 38a80bd6340c604ce190d117cbce1d6a6bcb72d4e3cf68a3126b412da5c92688

Bekijk VBA-code voor Massa en zwaartepunt
Attribute VB_Name = "MechifyMassReport"
' Mechify - massa en zwaartepunt, actieve configuratie.
' SolidWorks VBA: importeer via File > Import File en start main.
' Vereist opgelost, actueel part/assembly en juiste materiaalgegevens.
' Geen opslag of rebuild. Selectie wordt gewist om het volledige model te meten.
' Systeemwaarden: kg, m en m^3. Model-origin als referentie.
' API: https://help.solidworks.com/2017/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IModelDocExtension~CreateMassProperty.html
Option Explicit
Sub main()
    On Error GoTo Failed
    Dim app As SldWorks.SldWorks
    Dim doc As SldWorks.ModelDoc2
    Set app = Application.SldWorks
    Set doc = app.ActiveDoc
    If doc Is Nothing Then
        MsgBox "Open eerst een part of assembly.", vbExclamation
        Exit Sub
    End If
    If doc.GetType <> swDocPART And doc.GetType <> swDocASSEMBLY Then
        MsgBox "Deze macro is bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If
    doc.ClearSelection2 True
    Dim props As SldWorks.MassProperty
    Set props = doc.Extension.CreateMassProperty
    If props Is Nothing Then
        MsgBox "Geen massa-eigenschappen beschikbaar. Controleer de solid bodies.", vbExclamation
        Exit Sub
    End If
    props.UseSystemUnits = True
    Dim center As Variant
    center = props.CenterOfMass
    If IsEmpty(center) Then
        MsgBox "Geen zwaartepunt beschikbaar.", vbExclamation
        Exit Sub
    End If
    Dim report As String
    report = "Massa: " & Format(props.Mass, "0.000") & " kg" & vbCrLf
    report = report & "Volume: " & Format(props.Volume * 1000000000#, "0.000") & " mm^3" & vbCrLf
    report = report & "Zwaartepunt t.o.v. oorsprong (mm):" & vbCrLf
    report = report & "X: " & Format(center(0) * 1000#, "0.000") & vbCrLf
    report = report & "Y: " & Format(center(1) * 1000#, "0.000") & vbCrLf
    report = report & "Z: " & Format(center(2) * 1000#, "0.000") & vbCrLf
    report = report & "Controleer materialen en eventuele massa-overrides."
    MsgBox report, vbInformation, "Mechify - " & doc.GetTitle
    Exit Sub
Failed:
    MsgBox "Rapport kon niet worden gemaakt: " & Err.Description, vbExclamation, "Mechify"
End Sub

Configuraties in beeld

Toont alle configuratienamen van een part of assembly en markeert de actieve configuratie. Lange lijsten verschijnen in opeenvolgende vensters. Activeert of wijzigt geen configuraties. Start main.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
SolidWorks 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Rapporteert namen en actieve configuratie; onderdrukking, display states en derived configurations vallen buiten de controle.

SOLIDWORKS API — GetConfigurationNames ↗

Download .bas

SHA-256: cfc25611d4052256972484a6117d123b624c1380a7cd52bdb0bb284925f29916

Bekijk VBA-code voor Configuraties in beeld
Attribute VB_Name = "MechifyConfigurations"
' Mechify - alle configuratienamen, zonder activeren of rebuild.
' Importeer deze module via File > Import File en start main.
' De actieve configuratie is gemarkeerd. Lange lijsten worden verdeeld.
' API: https://help.solidworks.com/2019/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2~GetConfigurationNames.html
Option Explicit
Sub main()
    On Error GoTo Failed
    Dim app As SldWorks.SldWorks
    Dim doc As SldWorks.ModelDoc2
    Set app = Application.SldWorks
    Set doc = app.ActiveDoc
    If doc Is Nothing Then
        MsgBox "Open eerst een part of assembly.", vbExclamation
        Exit Sub
    End If
    If doc.GetType <> swDocPART And doc.GetType <> swDocASSEMBLY Then
        MsgBox "Deze macro is bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If
    Dim names As Variant
    names = doc.GetConfigurationNames
    If IsEmpty(names) Then
        MsgBox "Geen configuraties gevonden.", vbInformation
        Exit Sub
    End If
    Dim activeName As String
    activeName = doc.ConfigurationManager.ActiveConfiguration.Name
    Dim report As String, line As String, i As Long
    report = "Configuraties (* = actief):" & vbCrLf
    For i = LBound(names) To UBound(names)
        line = CStr(names(i))
        If line = activeName Then line = "* " & line
        If Len(report) + Len(line) > 850 Then
            MsgBox report, vbInformation, "Mechify - configuraties"
            report = "Vervolg:" & vbCrLf
        End If
        report = report & line & vbCrLf
    Next i
    MsgBox report, vbInformation, "Mechify - configuraties"
    Exit Sub
Failed:
    MsgBox "Rapport kon niet worden gemaakt: " & Err.Description, vbExclamation, "Mechify"
End Sub

Inventor 2024

Installeren: Alt+F11 (VBA-editor) > Insert > Module, plak de code.

Exporteer naar STEP

Slaat het actieve part of assembly op als .stp, naast het bestaande bestand.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Alleen opgeslagen parts/assemblies; vertaleropties en referenties zijn niet in Inventor getest.

Inventor API 2024 — TranslatorAddIn ↗

Download .bas

SHA-256: f313741700cbfe2f02938215479a7e10509053056bd3e72b4d419a0fcdc9aac8

Bekijk VBA-code voor Exporteer naar STEP
Attribute VB_Name = "ExportActiefNaarSTEP"
'
' Inventor 2024 VBA-macro — Exporteer actief document naar STEP
' https://www.mechify.nl/cad/macros
'
' Wat: slaat het actieve part of assembly op als .stp, naast het
' bestaande bestand, met dezelfde naam.
' Vereist: het document is al minstens één keer opgeslagen (heeft een pad).
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Alt+F11 (VBA-editor) > Insert > Module > plak deze code.
'
Option Explicit

Sub ExportActiefNaarSTEP()

    ' ActiveDocument raises when no document is open (it does not return
    ' Nothing), so check Documents.Count first rather than testing the
    ' result of ActiveDocument for Nothing.
    If ThisApplication.Documents.Count = 0 Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    If oDoc.DocumentType <> kPartDocumentObject And oDoc.DocumentType <> kAssemblyDocumentObject Then
        MsgBox "Deze macro is alleen bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If

    If oDoc.FullFileName = "" Then
        MsgBox "Sla het document eerst één keer op (nog geen bestandspad).", vbExclamation
        Exit Sub
    End If

    If InStrRev(oDoc.FullFileName, ".") = 0 Then
        MsgBox "Bestandspad heeft geen extensie.", vbExclamation
        Exit Sub
    End If

    ' Vaste, door Autodesk gedocumenteerde AddIn-id van de STEP-vertaler.
    Dim oStepTranslator As TranslatorAddIn
    ' ItemById RAISES wanneer de AddIn ontbreekt — het geeft geen Nothing terug.
    ' Zonder On Error is de vriendelijke melding hieronder onbereikbaar en
    ' krijgt de gebruiker een VBA-foutdialoog.
    On Error Resume Next
    Set oStepTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
    On Error GoTo 0

    If oStepTranslator Is Nothing Then
        MsgBox "STEP-vertaler niet gevonden. Controleer of deze AddIn actief is.", vbCritical
        Exit Sub
    End If

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    Dim oData As DataMedium
    Set oData = ThisApplication.TransientObjects.CreateDataMedium

    Dim stepPath As String
    stepPath = Left(oDoc.FullFileName, InStrRev(oDoc.FullFileName, ".")) & "stp"
    oData.FileName = stepPath

    ' Application protocol wordt hier vast gezet — anders bepaalt de laatst
    ' gebruikte UI-instelling stilzwijgend welk protocol de export gebruikt.
    ' Kies AP242 (moderne standaard) of AP214 (breder ondersteund, ouder);
    ' controleer de exacte enum-naam in de Inventor Object Browser (VBA-editor,
    ' F2) onder ApplicationProtocolTypeEnum voor jouw Inventor-versie.
    If oStepTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
        oOptions.Value("ApplicationProtocolType") = kAP242ApplicationProtocolType
    End If

    Call oStepTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)

    MsgBox "Opgeslagen als:" & vbCrLf & stepPath, vbInformation

End Sub

Sla alles op

Slaat elk geopend document met niet-opgeslagen wijzigingen op.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Slaat gewijzigde, reeds opgeslagen open documenten op; foutafhandeling en afhankelijkheden zijn niet in Inventor getest.

Inventor API 2024 — Document.Save ↗

Download .bas

SHA-256: d6583222f1173d8e806ac26dab6d7e0cbb3163959edfda60912dd09863db2e34

Bekijk VBA-code voor Sla alles op
Attribute VB_Name = "SlaAllesOp"
'
' Inventor 2024 VBA-macro — Sla alle gewijzigde open documenten op
' https://www.mechify.nl/cad/macros
'
' Wat: loopt door alle op dit moment geopende documenten en slaat elk
' document met niet-opgeslagen wijzigingen (Dirty) op. Documenten zonder
' wijzigingen worden overgeslagen.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Alt+F11 (VBA-editor) > Insert > Module > plak deze code.
'
Option Explicit

Sub SlaAllesOp()

    Dim oDoc As Document
    Dim saved As Integer
    Dim skipped As Integer
    saved = 0
    skipped = 0

    For Each oDoc In ThisApplication.Documents
        If oDoc.Dirty Then
            If oDoc.FullFileName = "" Then
                skipped = skipped + 1
            Else
                oDoc.Save
                saved = saved + 1
            End If
        Else
            skipped = skipped + 1
        End If
    Next

    MsgBox saved & " document(en) opgeslagen." & vbCrLf & _
           skipped & " overgeslagen (geen wijzigingen, of nog niet opgeslagen).", vbInformation

End Sub

Toon iProperties

Leest titel, auteur, onderwerp en trefwoorden uit het actieve document. Alleen-lezen.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Leest vier Summary Information-velden; overige iProperties en lokalisatiegedrag zijn niet in Inventor getest.

Inventor API 2024 — PropertySets ↗

Download .bas

SHA-256: d772e9edfac3b07386cf7fa7b542b02c90391f395dbc797406fd183ca0965c94

Bekijk VBA-code voor Toon iProperties
Attribute VB_Name = "ToonIProperties"
'
' Inventor 2024 VBA-macro — Toon iProperties van het actieve document
' https://www.mechify.nl/cad/macros
'
' Wat: leest Titel, Auteur, Onderwerp en Trefwoorden uit de
' samenvattingsgegevens (Summary) van het actieve document en toont ze
' in een berichtvenster. Alleen-lezen, wijzigt niets.
'
' Installeren: Alt+F11 (VBA-editor) > Insert > Module > plak deze code.
'
Option Explicit

Sub ToonIProperties()

    ' ActiveDocument raises when no document is open (it does not return
    ' Nothing), so check Documents.Count first.
    If ThisApplication.Documents.Count = 0 Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    Dim oSummary As PropertySet
    Set oSummary = oDoc.PropertySets.Item("Inventor Summary Information")

    Dim msg As String
    msg = "Titel: " & oSummary.Item("Title").Value & vbCrLf
    msg = msg & "Auteur: " & oSummary.Item("Author").Value & vbCrLf
    msg = msg & "Onderwerp: " & oSummary.Item("Subject").Value & vbCrLf
    msg = msg & "Trefwoorden: " & oSummary.Item("Keywords").Value

    MsgBox msg, vbInformation, "iProperties — " & oDoc.DisplayName

End Sub

Batch-export tekeningen naar PDF

Exporteert elke geopende, al opgeslagen tekening naar PDF.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Alleen open, opgeslagen tekeningen; PDF AddIn, sheets, fonts en referenties zijn niet in Inventor getest.

Inventor API 2024 — PDF Translator sample ↗

Download .bas

SHA-256: 3b49f1b913ffe83c9e09d8d051d4573e4d5eed8d7a00931264b92ff1620ba406

Bekijk VBA-code voor Batch-export tekeningen naar PDF
Attribute VB_Name = "BatchExportTekeningenNaarPDF"
'
' Inventor 2024 VBA-macro — Batch-export open tekeningen naar PDF
' https://www.mechify.nl/cad/macros
'
' Wat: loopt door alle op dit moment geopende documenten, en exporteert
' elke tekening (.idw/.dwg) die al een bestandspad heeft naar PDF, naast
' het bestaande bestand, met dezelfde naam.
' Parts en assemblies worden overgeslagen.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Alt+F11 (VBA-editor) > Insert > Module > plak deze code.
'
Option Explicit

Sub BatchExportTekeningenNaarPDF()

    ' Vaste, door Autodesk gedocumenteerde AddIn-id van de PDF-vertaler.
    Dim oPDFAddIn As TranslatorAddIn
    ' ItemById RAISES wanneer de AddIn ontbreekt (geeft geen Nothing terug),
    ' dus zonder On Error is de melding hieronder onbereikbaar.
    On Error Resume Next
    Set oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    On Error GoTo 0

    If oPDFAddIn Is Nothing Then
        MsgBox "PDF-vertaler niet gevonden. Controleer of deze AddIn actief is.", vbCritical
        Exit Sub
    End If

    Dim oDoc As Document
    Dim exported As Integer
    Dim skipped As Integer
    Dim failures As String
    exported = 0
    skipped = 0
    failures = ""

    For Each oDoc In ThisApplication.Documents

        If oDoc.DocumentType = kDrawingDocumentObject Then

            If oDoc.FullFileName = "" Or InStrRev(oDoc.FullFileName, ".") = 0 Then
                skipped = skipped + 1
            Else

                Dim pdfPath As String
                pdfPath = Left(oDoc.FullFileName, InStrRev(oDoc.FullFileName, ".")) & "pdf"

                Dim oContext As TranslationContext
                Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
                oContext.Type = kFileBrowseIOMechanism

                Dim oOptions As NameValueMap
                Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

                Dim oData As DataMedium
                Set oData = ThisApplication.TransientObjects.CreateDataMedium
                oData.FileName = pdfPath

                If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
                    ' Standaardopties van de vertaler.
                End If

                On Error Resume Next
                Call oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oData)
                If Err.Number = 0 Then
                    exported = exported + 1
                Else
                    ' Bewaar WAAROM dit document faalde. Zonder dit wordt elke
                    ' oorzaak — vergrendeld bestand, ontbrekende referentie,
                    ' volle schijf — hetzelfde nietszeggende "overgeslagen".
                    skipped = skipped + 1
                    failures = failures & vbCrLf & "- " & oDoc.DisplayName & ": " & Err.Description
                    Err.Clear
                End If
                On Error GoTo 0

            End If

        End If

    Next oDoc

    Dim msg As String
    msg = exported & " tekening(en) geëxporteerd naar PDF." & vbCrLf & _
          skipped & " overgeslagen (geen tekening, of nog niet opgeslagen)."
    If Len(failures) > 0 Then
        msg = msg & vbCrLf & vbCrLf & "Mislukt:" & failures
    End If
    MsgBox msg, vbInformation

End Sub

Exporteer vlak patroon naar DXF

Slaat het vlakke patroon van een plaatwerk-part op als .dxf.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Vereist een opgeslagen plaatwerk-part; DXF-opties, layer mapping en herstel na fouten zijn niet in Inventor getest.

Inventor API 2024 — DataIO.WriteDataToFile ↗

Download .bas

SHA-256: 64e700e07b6e8f5f79d080abb9bb7db9cf695b3d1fc0a3e1a12bf9ade4a824d1

Bekijk VBA-code voor Exporteer vlak patroon naar DXF
Attribute VB_Name = "ExporteerVlakPatroonNaarDXF"
'
' Inventor 2024 VBA-macro — Exporteer vlak patroon naar DXF
' https://www.mechify.nl/cad/macros
'
' Wat: van het actieve plaatwerk-part wordt het vlakke patroon (Flat
' Pattern) opgeslagen als .dxf naast het bestaande bestand, met dezelfde
' naam. Ontvouwt het vlakke patroon automatisch als dat nog niet bestaat.
' Vereist: het actieve document is een plaatwerk-part (Sheet Metal), en
' is al minstens één keer opgeslagen.
' Zie ook de rekenhulp Richtlijnen kanten op deze site voor Ri,
' beenlengte en Z-buiging bij het plaatwerkontwerp zelf.
' Basis-hulpmiddel, geen productiecode. Test eerst op een kopie.
'
' Installeren: Alt+F11 (VBA-editor) > Insert > Module > plak deze code.
'
Option Explicit

' Vertaleropties hier aanpassen, niet verderop in de functie.
Private Const ACAD_VERSION As String = "2010"
Private Const OUTER_PROFILE_LAYER As String = "IV_OUTER_PROFILE"

Sub ExporteerVlakPatroonNaarDXF()

    ' ActiveDocument raises when no document is open (it does not return
    ' Nothing), so check Documents.Count first.
    If ThisApplication.Documents.Count = 0 Then
        MsgBox "Geen actief document.", vbExclamation
        Exit Sub
    End If

    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    If oDoc.DocumentType <> kPartDocumentObject Then
        MsgBox "Geen part-document. Open een plaatwerk-part.", vbExclamation
        Exit Sub
    End If

    If oDoc.FullFileName = "" Then
        MsgBox "Sla het document eerst één keer op (nog geen bestandspad).", vbExclamation
        Exit Sub
    End If

    Dim oPartDoc As PartDocument
    Set oPartDoc = oDoc

    ' Vaste, door Autodesk gedocumenteerde subtype-id van een
    ' plaatwerk-part (Sheet Metal).
    If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        MsgBox "Geen plaatwerk-part (Sheet Metal).", vbExclamation
        Exit Sub
    End If

    Dim oCompDef As SheetMetalComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    ' Onthoud of het vlakke patroon al bestond — zo niet, ruim het na export
    ' weer op zodat het document niet gewijzigd (dirty) achterblijft, net als
    ' de SolidWorks-twin die de suppress-staat terugzet.
    Dim createdFlatPattern As Boolean
    createdFlatPattern = Not oCompDef.HasFlatPattern

    If createdFlatPattern Then
        oCompDef.Unfold
    End If

    Dim oFlatPattern As FlatPattern
    Set oFlatPattern = oCompDef.FlatPattern

    If InStrRev(oDoc.FullFileName, ".") = 0 Then
        MsgBox "Bestandspad heeft geen extensie.", vbExclamation
        GoTo Cleanup
    End If

    Dim dxfPath As String
    dxfPath = Left(oDoc.FullFileName, InStrRev(oDoc.FullFileName, ".")) & "dxf"

    Dim sOptions As String
    sOptions = "FLAT PATTERN DXF?AcadVersion=" & ACAD_VERSION & "&OuterProfileLayer=" & OUTER_PROFILE_LAYER

    ' On Error Resume Next + explicit Err check, not On Error GoTo, so the
    ' Cleanup label below always runs next regardless of success or failure —
    ' a raised error here used to skip straight past oFlatPattern.Delete,
    ' leaving a flat pattern this macro created (and the document marked
    ' dirty) behind on export failure (E17, 16 sept 2026 review).
    Dim exportErrorDescription As String
    On Error Resume Next
    oFlatPattern.DataIO.WriteDataToFile sOptions, dxfPath
    If Err.Number <> 0 Then exportErrorDescription = Err.Description
    On Error GoTo 0

    If exportErrorDescription = "" Then
        MsgBox "Opgeslagen als:" & vbCrLf & dxfPath, vbInformation
    Else
        MsgBox "Exporteren mislukt: " & exportErrorDescription, vbCritical
    End If

Cleanup:
    If createdFlatPattern Then
        On Error Resume Next
        oFlatPattern.Delete
        On Error GoTo 0
    End If

End Sub

Massa en zwaartepunt

Rapporteert kg, mm³ en zwaartepunt in mm voor de actieve modeltoestand van een part of assembly. Signaleert een massa-override. Controleer materialen; slaat geen document op. Start MassaRapport.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Uitkomst hangt af van actuele geometrie, materiaal, overrides en model state; eenheden/API-aanroepen zijn alleen statisch beoordeeld.

Inventor API 2024 — MassProperties ↗

Download .bas

SHA-256: e2b1099d918d0ab1d1301a1eb2d6f6de12813ba5ced14db1b04353b59ead0fd3

Bekijk VBA-code voor Massa en zwaartepunt
Attribute VB_Name = "MechifyMassaRapport"
' Mechify - massa, volume en zwaartepunt van actieve modeltoestand.
' Inventor VBA: importeer .bas via de VBA-editor en start MassaRapport.
' Vereist actueel part/assembly met juist toegewezen materialen.
' Geen documentopslag; berekende massa wordt niet gecachet.
' Database-eenheden: kg, cm en cm^3; afstanden worden mm.
' API: https://help.autodesk.com/cloudhelp/2024/ENU/Inventor-API/files/MassProperties.htm
Option Explicit
Sub MassaRapport()
    On Error GoTo Failed
    If ThisApplication.Documents.Count = 0 Then
        MsgBox "Open eerst een part of assembly.", vbExclamation
        Exit Sub
    End If
    Dim doc As Object
    Set doc = ThisApplication.ActiveDocument
    If doc.DocumentType <> kPartDocumentObject And doc.DocumentType <> kAssemblyDocumentObject Then
        MsgBox "Deze macro is bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If
    Dim props As MassProperties
    Set props = doc.ComponentDefinition.MassProperties
    props.CacheResultsOnCompute = False
    Dim center As Point
    Set center = props.CenterOfMass
    Dim report As String
    report = "Massa: " & Format(props.Mass, "0.000") & " kg" & vbCrLf
    report = report & "Volume: " & Format(props.Volume * 1000#, "0.000") & " mm^3" & vbCrLf
    report = report & "Zwaartepunt t.o.v. oorsprong (mm):" & vbCrLf
    report = report & "X: " & Format(center.X * 10#, "0.000") & vbCrLf
    report = report & "Y: " & Format(center.Y * 10#, "0.000") & vbCrLf
    report = report & "Z: " & Format(center.Z * 10#, "0.000") & vbCrLf
    report = report & "Massa overschreven: " & CStr(props.MassOverridden) & vbCrLf
    report = report & "Controleer materialen en actieve modeltoestand."
    MsgBox report, vbInformation, "Mechify - " & doc.DisplayName
    Exit Sub
Failed:
    MsgBox "Rapport kon niet worden gemaakt: " & Err.Description, vbExclamation, "Mechify"
End Sub

Gebruikersparameters rapporteren

Leest namen, expressies en eenheden van UserParameters in het actieve part of assembly, inclusief tekst en booleans. Modelparameters vallen buiten dit rapport. Verdeelt lange lijsten over vensters. Start ParameterRapport.

Validatiestatus: broncode statisch beoordeeld

Doelomgeving
Inventor 2024
Bronreview
2026-09-27
Volgende review uiterlijk
2027-03-27
Uitgevoerd in CAD
Nee

Alleen UserParameters van part/assembly; modelparameters, locale-opmaak en lange rapporten zijn niet in Inventor getest.

Inventor API 2024 — UserParameter.Expression ↗

Download .bas

SHA-256: 2c804627fa8e63a6a7934216d0c85228e5151f07b847ee97db1c994d55c11f6a

Bekijk VBA-code voor Gebruikersparameters rapporteren
Attribute VB_Name = "MechifyParameters"
' Mechify - overzicht gebruikersparameters, formules en eenheden.
' Inventor VBA: importeer via File > Import File, start ParameterRapport.
' Leest UserParameters van actief part/assembly; geen modelparameters.
' Expression blijft intact, ook voor tekst en booleans. Geen conversie.
' Lange lijsten worden verdeeld; geen waarden aangepast of opgeslagen.
' API: https://help.autodesk.com/cloudhelp/2024/ENU/Inventor-API/files/UserParameter_Expression.htm
Option Explicit
Sub ParameterRapport()
    On Error GoTo Failed
    If ThisApplication.Documents.Count = 0 Then
        MsgBox "Open eerst een part of assembly.", vbExclamation
        Exit Sub
    End If
    Dim doc As Object
    Set doc = ThisApplication.ActiveDocument
    If doc.DocumentType <> kPartDocumentObject And doc.DocumentType <> kAssemblyDocumentObject Then
        MsgBox "Deze macro is bedoeld voor een part of assembly.", vbExclamation
        Exit Sub
    End If
    Dim params As UserParameters
    Set params = doc.ComponentDefinition.Parameters.UserParameters
    If params.Count = 0 Then
        MsgBox "Geen gebruikersparameters gevonden.", vbInformation
        Exit Sub
    End If
    Dim param As UserParameter
    Dim report As String, line As String
    report = "Naam = expressie [eenheid]" & vbCrLf
    For Each param In params
        line = param.Name & " = " & param.Expression & " [" & param.Units & "]"
        If Len(report) + Len(line) > 850 Then
            If Len(report) > 0 Then MsgBox report, vbInformation, "Mechify - parameters"
            report = ""
        End If
        ' Ook een uitzonderlijk lange expressie blijft volledig beschikbaar.
        Do While Len(line) > 850
            MsgBox Left$(line, 850), vbInformation, "Mechify - parameter (vervolg)"
            line = Mid$(line, 851)
        Loop
        report = report & line & vbCrLf
    Next param
    If Len(report) > 0 Then MsgBox report, vbInformation, "Mechify - parameters"
    Exit Sub
Failed:
    MsgBox "Rapport kon niet worden gemaakt: " & Err.Description, vbExclamation, "Mechify"
End Sub

Vragen

Waarom .bas-bestanden?+

Dat is het standaard tekstformaat voor een VBA-module. Open de VBA-editor, voeg een module toe en plak de code, of importeer het .bas-bestand direct.

Werkt dit ook in oudere versies?+

Geschreven voor 2024, maar de gebruikte API's zijn al jaren stabiel. Waarschijnlijk werkt het ook in 2021–2023; niet getest.

Zijn dit productie-macro's?+

Nee. Basis-hulpmiddelen zonder foutafhandeling voor edge cases. Test eerst op een kopie, niet op een kritiek bestand.

Moet ik macro's inschakelen?+

Ja, via het Trust Center (SolidWorks) of de macro-instellingen (Inventor). Macro's uit onbekende bron staan standaard uit.