I am trying to develop a macro which will sum up all dimension greater than a specific values in all the sketches of an assembly and export that value to a Text file. Anyone can help will be appreciated.
All sketches in the assembly feature tree or all sketches in all components?
I am after sketches in all components as well as in assembly. I have cracked down for sketches in a part that has dimension specified into it. But I can not find if the dimension of sketch that is referencing from other models rather defined into the sketch itself. Thanks.
perhaps what your end goal is will help.
sketches can be unreliable as patterns will not have sketches defining edges, if your just looking for a minimum radius that is different.
using Edges is a much more reliable way to go about this.
so your end goal with this macro will help us help you.
Yes you are correct. I have cracked down for the part. But if physical dimension is not there ie referring to other model, I am not getting the values. Thanks for your input.
This should print all dimensions. Kindly keep the macro header notes if you'd like to share with others.You can modify the macro to save the dims in a text file. That's fairly easy to do.
' CADHero.com - SOLIDWORKS API CONSULTING AND TRAINING
' Print all sketch dimension
' written by JLILI Amen
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssembly As SldWorks.AssemblyDoc
Dim swComponent As SldWorks.Component2
Dim Components As Variant
Dim swModelFromComponent As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Dim Features As Variant
Dim swDisplayDimension As SldWorks.DisplayDimension
Dim swDimension As SldWorks.Dimension
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssembly = swModel
Components = swAssembly.GetComponents(False)
For Each swComponentObject In Components
Set swComponent = swComponentObject
Debug.Print "Component Name = " & swComponent.Name2
Set swModelFromComponent = swComponent.GetModelDoc2
If Not swModelFromComponent Is Nothing Then
Features = swModelFromComponent.FeatureManager.GetFeatures(False)
For Each swFeatureObject In Features
Set swFeature = swFeatureObject
If swFeature.GetTypeName2 = "ProfileFeature" Or swFeature.GetTypeName2 = "3DProfileFeature" Then
Set swDisplayDimension = swFeature.GetFirstDisplayDimension
While Not swDisplayDimension Is Nothing
Set swDimension = swDisplayDimension.GetDimension2(0)
Debug.Print vbTab + "Configuration Name = " + swComponent.ReferencedConfiguration
Debug.Print vbTab + "Sketch Name = " + swFeature.Name
Debug.Print vbTab + vbTab + "Dimension Name = " + swDimension.Name
Debug.Print vbTab + vbTab + "Value = " + CStr(swDimension.Value)
Set swDisplayDimension = swFeature.GetNextDisplayDimension(swDisplayDimension)
Retrieving data ...