Differentiate enabled vs disabled parts in Assembly using VBA

Differentiate enabled vs disabled parts in Assembly using VBA

Anonymous
Not applicable
525 Views
6 Replies
Message 1 of 7

Differentiate enabled vs disabled parts in Assembly using VBA

Anonymous
Not applicable
I have an assembly where I count parts and place them in a database.
Currently, I am counting all parts (by name). I would like to exclude the
parts where the snabled feature is turned off in the specific assembly.

For Each oPCompRef In oPCompRefs

PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
QTY = oPCompRef.ImmediateOccurrences.Count

I am thinking possibly, that changing the QTY variable to ount differently
might be a viable solution. On the other hand, perhaps there is another if
agrument that must be added???

Thanks in advance for your help!


Steve Anderson
Engineer / Documentation Coordinator _
METRO MACHINE & ENGINEERING CORP.
vmail: (952) 259-3683 fax: (952) 937-2374
email: sanders.tec@netzero.com

-- NOTE NEW EMAIL ADDRESS --
0 Likes
526 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
If I understand correctly it should just be something like this

> For Each oPCompRef In oPCompRefs
>
> PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
if oPCompRef.Enabled = True then
> QTY = oPCompRef.ImmediateOccurrences.Count
end if


--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program


"Stephen Anderson" wrote in message
news:45822FE41694A75528C8C449DDCA30DE@in.WebX.maYIadrTaRb...
> I have an assembly where I count parts and place them in a database.
> Currently, I am counting all parts (by name). I would like to exclude the
> parts where the snabled feature is turned off in the specific assembly.
>
> For Each oPCompRef In oPCompRefs
>
> PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> QTY = oPCompRef.ImmediateOccurrences.Count
>
> I am thinking possibly, that changing the QTY variable to ount differently
> might be a viable solution. On the other hand, perhaps there is another if
> agrument that must be added???
>
> Thanks in advance for your help!
>
>
> Steve Anderson
> Engineer / Documentation Coordinator _
> METRO MACHINE & ENGINEERING CORP.
> vmail: (952) 259-3683 fax: (952) 937-2374
> email: sanders.tec@netzero.com
>
> -- NOTE NEW EMAIL ADDRESS --
>
>
0 Likes
Message 3 of 7

Anonymous
Not applicable
Kent is close, but there's a slight change that's needed. Try this:

Public Sub CountEnabled()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oCompRef As ComponentDefinitionReference
For Each oCompRef In
oDoc.ComponentDefinition.ImmediateReferencedDefinitions
Dim iQty As Long
iQty = 0
Dim oOcc As ComponentOccurrence
For Each oOcc In oCompRef.ImmediateOccurrences
If oOcc.Enabled Then
iQty = iQty + 1
End If
Next

Dim strPartNo As String
strPartNo = Left((oCompRef.ReferencedFileDescriptor.DisplayName),
Len(oCompRef.ReferencedFileDescriptor.DisplayName) - 4)

Debug.Print strPartNo & ", Qty: " & iQty
Next
End Sub

--
Brian Ekins
Developer Technical Services, Autodesk
Discussion Q&A: http://www.autodesk.com/discussion


"Kent Keller" wrote in message
news:BDB8F35A0F117F4202EBE876A5D12228@in.WebX.maYIadrTaRb...
> If I understand correctly it should just be something like this
>
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> if oPCompRef.Enabled = True then
> > QTY = oPCompRef.ImmediateOccurrences.Count
> end if
>
>
> --
> Kent
> Assistant Moderator
> Autodesk Discussion Forum Moderator Program
>
>
> "Stephen Anderson" wrote in message
> news:45822FE41694A75528C8C449DDCA30DE@in.WebX.maYIadrTaRb...
> > I have an assembly where I count parts and place them in a database.
> > Currently, I am counting all parts (by name). I would like to exclude
the
> > parts where the snabled feature is turned off in the specific assembly.
> >
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> > QTY = oPCompRef.ImmediateOccurrences.Count
> >
> > I am thinking possibly, that changing the QTY variable to ount
differently
> > might be a viable solution. On the other hand, perhaps there is another
if
> > agrument that must be added???
> >
> > Thanks in advance for your help!
> >
> >
> > Steve Anderson
> > Engineer / Documentation Coordinator _
> > METRO MACHINE & ENGINEERING CORP.
> > vmail: (952) 259-3683 fax: (952) 937-2374
> > email: sanders.tec@netzero.com
> >
> > -- NOTE NEW EMAIL ADDRESS --
> >
> >
>
>
0 Likes
Message 4 of 7

Anonymous
Not applicable
oPCompRef.Enabled - produces a runtime error 438 - Object doesn't support
property or method.

My quesion is, what if there are three identical parts and only two are
enabled? Can the count work differently? If not, I can deal with it, but
what exactly is missing from your if statement below?

Thanks for your response!



"Kent Keller" wrote in message
news:BDB8F35A0F117F4202EBE876A5D12228@in.WebX.maYIadrTaRb...
> If I understand correctly it should just be something like this
>
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> if oPCompRef.Enabled = True then
> > QTY = oPCompRef.ImmediateOccurrences.Count
> end if
>
>
> --
> Kent
> Assistant Moderator
> Autodesk Discussion Forum Moderator Program
>
>
> "Stephen Anderson" wrote in message
> news:45822FE41694A75528C8C449DDCA30DE@in.WebX.maYIadrTaRb...
> > I have an assembly where I count parts and place them in a database.
> > Currently, I am counting all parts (by name). I would like to exclude
the
> > parts where the snabled feature is turned off in the specific assembly.
> >
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> > QTY = oPCompRef.ImmediateOccurrences.Count
> >
> > I am thinking possibly, that changing the QTY variable to ount
differently
> > might be a viable solution. On the other hand, perhaps there is another
if
> > agrument that must be added???
> >
> > Thanks in advance for your help!
> >
> >
> > Steve Anderson
> > Engineer / Documentation Coordinator _
> > METRO MACHINE & ENGINEERING CORP.
> > vmail: (952) 259-3683 fax: (952) 937-2374
> > email: sanders.tec@netzero.com
> >
> > -- NOTE NEW EMAIL ADDRESS --
> >
> >
>
>
0 Likes
Message 5 of 7

Anonymous
Not applicable
What version are you on? In R6 and earlier help there was a really nice little example of
iterating through subs and counting. I don't have it here, and don't have time to
recreate it, but I could post a copy tonight if no one else does.

It has two subs, one that does all the top level components, and the second one iterates
through all the subs components. In this second one you should be able to skip the
count simply by checking if the component is enabled or not and using that to decide if
you wanted it added to the count or not.

--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program


"Stephen Anderson" wrote in message
news:DBBB12277B7E0E3C20925B8AC081BD5F@in.WebX.maYIadrTaRb...
> oPCompRef.Enabled - produces a runtime error 438 - Object doesn't support
> property or method.
>
> My quesion is, what if there are three identical parts and only two are
> enabled? Can the count work differently? If not, I can deal with it, but
> what exactly is missing from your if statement below?
>
> Thanks for your response!
0 Likes
Message 6 of 7

Anonymous
Not applicable
Actually Kent go ahead and post it. I'm going to need something close to it
in a few week for a work project.

--
Sean Dotson, PE
http://www.sdotson.com
Check the Inventor FAQ for most common questions
www.sdotson.com/faq.html
-----------------------------------------------------------------------
"Kent Keller" wrote in message
news:9756EE21134BE540FEEA905780A9AC03@in.WebX.maYIadrTaRb...
> What version are you on? In R6 and earlier help there was a really nice
little example of
> iterating through subs and counting. I don't have it here, and don't
have time to
> recreate it, but I could post a copy tonight if no one else does.
>
> It has two subs, one that does all the top level components, and the
second one iterates
> through all the subs components. In this second one you should be able
to skip the
> count simply by checking if the component is enabled or not and using that
to decide if
> you wanted it added to the count or not.
>
> --
> Kent
> Assistant Moderator
> Autodesk Discussion Forum Moderator Program
>
>
> "Stephen Anderson" wrote in message
> news:DBBB12277B7E0E3C20925B8AC081BD5F@in.WebX.maYIadrTaRb...
> > oPCompRef.Enabled - produces a runtime error 438 - Object doesn't
support
> > property or method.
> >
> > My quesion is, what if there are three identical parts and only two are
> > enabled? Can the count work differently? If not, I can deal with it,
but
> > what exactly is missing from your if statement below?
> >
> > Thanks for your response!
>
>
0 Likes
Message 7 of 7

Anonymous
Not applicable
Neither of these work, nor your example of oPCompRef.Enabled. Any other
ideas?

oPCompRef.ReferencedDefinition.Occurrences.Item.Enabled

oPCompRef.ImmediateOccurrences.Item.Enabled



Thanks for your help on this!





"Kent Keller" wrote in message
news:BDB8F35A0F117F4202EBE876A5D12228@in.WebX.maYIadrTaRb...
> If I understand correctly it should just be something like this
>
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> if oPCompRef.Enabled = True then
> > QTY = oPCompRef.ImmediateOccurrences.Count
> end if
>
>
> --
> Kent
> Assistant Moderator
> Autodesk Discussion Forum Moderator Program
>
>
> "Stephen Anderson" wrote in message
> news:45822FE41694A75528C8C449DDCA30DE@in.WebX.maYIadrTaRb...
> > I have an assembly where I count parts and place them in a database.
> > Currently, I am counting all parts (by name). I would like to exclude
the
> > parts where the snabled feature is turned off in the specific assembly.
> >
> > For Each oPCompRef In oPCompRefs
> >
> > PartNo = Left((oPCompRef.ReferencedFileDescriptor.DisplayName),
> > Len(oPCompRef.ReferencedFileDescriptor.DisplayName) - 4)
> > QTY = oPCompRef.ImmediateOccurrences.Count
> >
> > I am thinking possibly, that changing the QTY variable to ount
differently
> > might be a viable solution. On the other hand, perhaps there is another
if
> > agrument that must be added???
> >
> > Thanks in advance for your help!
> >
> >
> > Steve Anderson
> > Engineer / Documentation Coordinator _
> > METRO MACHINE & ENGINEERING CORP.
> > vmail: (952) 259-3683 fax: (952) 937-2374
> > email: sanders.tec@netzero.com
> >
> > -- NOTE NEW EMAIL ADDRESS --
> >
> >
>
>
0 Likes