VB API question

Option Explicit

Sub TraverseComponent ( swComp As SldWorks.Component2, nLevel As Long )

Dim vChildComp As Variant

Dim swChildComp As SldWorks.Component2

Dim swCompConfig As SldWorks.Configuration

Dim sPadStr As String

Dim i As Long

dim CompModeldoc2 as modeldoc2

For i = 0 To nLevel - 1

sPadStr = sPadStr + " "

Next i

vChildComp = swComp.GetChildren

For i = 0 To UBound(vChildComp)

Set swChildComp = vChildComp(i)

TraverseComponent swChildComp, nLevel + 1

set CompModeldoc2 = swchildcomp.getmodeldoc

Next i

End Sub

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swAssy As SldWorks.AssemblyDoc

Dim swConf As SldWorks.configuration

Dim swRootComp As SldWorks.Component2

Dim bRet As Boolean

Set swApp = CreateObject("SldWorks.Application")

Set swModel = swApp.ActiveDoc

Set swConf = swModel.GetActiveConfiguration

Set swRootComp = swConf.GetRootComponent

Debug.Print "File = " & swModel.GetPathName

TraverseComponent swRootComp, 1

End Sub

'---------------------------------------

Reply to
Sean Phillips
Loading thread data ...

Sean's code is correct to traverse the assembly, but don't forget swchildcomp.SetSuppression swComponentFullyResolved ' in case it is lightweight before calling GetModelDoc then you can add all the custom properties of the modeldoc, optionally using the result of Component2::ReferencedConfiguration to scan properties specific to that component's configuration.

Now I understand that you followed a different track and already have a list of part documents paths. If you want to load them without making them active, there is a trick: Call SldWorks.DocumentVisible ( false, swDocPART) ' will not show part docs loaded after that Set doc=SldWorks.OpenDoc2(path,swDocPART,readonly,viewonly,silent,errors) Call SldWorks.DocumentVisible ( true, swDocPART)' ' will show part docs again

Reply to
Philippe Guglielmetti

The closest to the actual page of the one Im playing with is:

formatting link

Look down near the bottom of the page for " OLE Structured Storage Component "

Good Luck!

Reply to
rocheey

well, I was amazed at how much infornation is stored there.. feature modification times/dates, the parasolid models themselves, the last few paths you've saved the document in... in poking around other files, like Excel, etc, theres not much there. This also explains why after you delete 49 of 50 configurations in a part file, the file only shrinks 5k or so haa haaa

solution...

The operative word here is 'practical', and I agree on that point. Quickly developing maintainable code is one of the selling points of VB(A), and one might get just as much a speed increase from *loading* the document in a 'C' routine than grabbing bytes out of a binary header using VB.

But there are some times when reading the storage may be the only way, or the only practical way. I started doing it because, while my company uses derived configurations on virtually *every part* made, they have refused to upgrade even from 2003 sp0 to 2003 sp1 (we have the 2004 disks still sitting around)

its not until 2003 sp1 that the 'isderived' function appeared...

Reply to
rocheey

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.