Accessing Sketch and Part Object In Assembly

Accessing Sketch and Part Object In Assembly

Anonymous
Not applicable
333 Views
3 Replies
Message 1 of 4

Accessing Sketch and Part Object In Assembly

Anonymous
Not applicable
What I'm trying to do is make a program that will insert our company's
standard hole sizes nto a part or into an edited part in an assembly file.
Some background info on how it should work. The user puts a sketch on a
plane or planar surface and draws hole points where they want. They run the
hole program and the program iterates through tht open sketch finds the hole
points and adds the holes and closes the sketch. The code I have below
works fine for a part file, but when I am editing a part in an assembly
file, as soon as I try to get the selectset or anything else from the edited
part it crashes. I have checked the enumeration value of the of the
document type object in both cases and they both return
kPartDocumentObject. The program seems to fail in the selPoints function
where I check if the user has selected anything and add the hole points to
an object collection. My main question is has anybody done something
similar either in VB or in VC++ and got it to work for both a single part
and a part in an assembly? Any help would be appreciated

Josh

// Getting the active document.
CComPtr pDoc;
CComQIPtr pAssyDoc;
CComQIPtr pPartCompDef;
CComPtr pHolePoints;

HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
if (FAILED(hr))
{
AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
return hr;
}

// Checking document type.
DocumentTypeEnum docType;
pDoc->get_DocumentType(&docType);

// Is the active document a part document.
if(docType == kPartDocumentObject)
{
pPartDoc = pDoc;

// Getting component definition.
hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
if(FAILED(hr))
{
AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
return hr;
}
}
else if (docType == kAssemblyDocumentObject)
{
CComPtr pAssyCompDef;
CComPtr pActiveOcc;

pAssyDoc = pDoc;

hr = pAssyDoc->get_ComponentDefinition(&pAssyCompDef);
if (FAILED(hr))
{
AfxMessageBox(_T("get_ComponentDefinition Failed!"));
return hr;
}

hr = pAssyCompDef->get_ActiveOccurrence(&pActiveOcc);
if (FAILED(hr))
{
AfxMessageBox(_T("get_ActiveOccurrence Failed!"));
return hr;
}

DocumentTypeEnum assyDocType;
pActiveOcc->get_DefinitionDocumentType(&assyDocType);

if(assyDocType == kPartDocumentObject)
{

// Getting component definition
CComPtr pCompDef;
hr = pActiveOcc->get_Definition(&pCompDef);
if(FAILED(hr))
{
AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
return hr;
}

pPartDoc = pActiveOcc;
pPartCompDef = pCompDef;

}

}

// Get selection and add holes.
hr = selPoints(pHolePoints);
if(FAILED(hr)) return hr;
0 Likes
334 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Josh,

This was an interesting problem. Below is some code that I think does what
you want. I ran into one issue with Inventor not returning from the sketch
environment after creating the feature. I've logged a defect for this but
was also able to workaround it by calling the "Return" command explicitly.

Public Sub CreateHoles()
' Check to see that a sketch is the active edit object.
Dim oSketch As PlanarSketch
If TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
' Check to see that the sketch is in a part document and not an
assembly.
' This is because assembly features are not currently supported.
If TypeOf ThisApplication.ActiveEditObject.Parent Is
PartComponentDefinition Then
Set oSketch = ThisApplication.ActiveEditObject
Else
MsgBox "A part sketch with hole centers must be active."
Exit Sub
End If
ElseIf TypeOf ThisApplication.ActiveEditObject Is PartDocument Then
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveEditObject
If TypeOf oPartDoc.ActivatedObject Is PlanarSketch Then
Set oSketch = oPartDoc.ActivatedObject
Else
MsgBox "A part sketch with hole centers must be active."
Exit Sub
End If
Else
MsgBox "A part sketch with hole centers must be active."
Exit Sub
End If


' Find all of the hole centers on the sketch and add them to the
collection.
Dim oHoleCenters As ObjectCollection
Set oHoleCenters =
ThisApplication.TransientObjects.CreateObjectCollection

Dim oPoint As SketchPoint
For Each oPoint In oSketch.SketchPoints
If oPoint.HoleCenter Then
oHoleCenters.Add oPoint
End If
Next

' Create the hole feature.
Dim oPartCompDef As PartComponentDefinition
Set oPartCompDef = oSketch.Parent
Call
oPartCompDef.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenters,
2, 2, kPositiveExtentDirection)

' When editing a part in-place within an assembly, it's not correctly
' exiting the sketch environment when the feature is created. This
' forces the exit.
If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
ThisApplication.CommandManager.[_StartCommand] 44011
End If
End Sub

-Brian

"Josh Tiffin" wrote in message
news:E214B43F7DDE923EB16DA791CE50CE7B@in.WebX.maYIadrTaRb...
> What I'm trying to do is make a program that will insert our company's
> standard hole sizes nto a part or into an edited part in an assembly file.
> Some background info on how it should work. The user puts a sketch on a
> plane or planar surface and draws hole points where they want. They run
the
> hole program and the program iterates through tht open sketch finds the
hole
> points and adds the holes and closes the sketch. The code I have below
> works fine for a part file, but when I am editing a part in an assembly
> file, as soon as I try to get the selectset or anything else from the
edited
> part it crashes. I have checked the enumeration value of the of the
> document type object in both cases and they both return
> kPartDocumentObject. The program seems to fail in the selPoints function
> where I check if the user has selected anything and add the hole points to
> an object collection. My main question is has anybody done something
> similar either in VB or in VC++ and got it to work for both a single part
> and a part in an assembly? Any help would be appreciated
>
> Josh
>
> // Getting the active document.
> CComPtr pDoc;
> CComQIPtr pAssyDoc;
> CComQIPtr pPartCompDef;
> CComPtr pHolePoints;
>
> HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
> if (FAILED(hr))
> {
> AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
> return hr;
> }
>
> // Checking document type.
> DocumentTypeEnum docType;
> pDoc->get_DocumentType(&docType);
>
> // Is the active document a part document.
> if(docType == kPartDocumentObject)
> {
> pPartDoc = pDoc;
>
> // Getting component definition.
> hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
> if(FAILED(hr))
> {
> AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> return hr;
> }
> }
> else if (docType == kAssemblyDocumentObject)
> {
> CComPtr pAssyCompDef;
> CComPtr pActiveOcc;
>
> pAssyDoc = pDoc;
>
> hr = pAssyDoc->get_ComponentDefinition(&pAssyCompDef);
> if (FAILED(hr))
> {
> AfxMessageBox(_T("get_ComponentDefinition Failed!"));
> return hr;
> }
>
> hr = pAssyCompDef->get_ActiveOccurrence(&pActiveOcc);
> if (FAILED(hr))
> {
> AfxMessageBox(_T("get_ActiveOccurrence Failed!"));
> return hr;
> }
>
> DocumentTypeEnum assyDocType;
> pActiveOcc->get_DefinitionDocumentType(&assyDocType);
>
> if(assyDocType == kPartDocumentObject)
> {
>
> // Getting component definition
> CComPtr pCompDef;
> hr = pActiveOcc->get_Definition(&pCompDef);
> if(FAILED(hr))
> {
> AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> return hr;
> }
>
> pPartDoc = pActiveOcc;
> pPartCompDef = pCompDef;
>
> }
>
> }
>
> // Get selection and add holes.
> hr = selPoints(pHolePoints);
> if(FAILED(hr)) return hr;
>
>
0 Likes
Message 3 of 4

Anonymous
Not applicable
Brian

Thanks for the response. I managed to put together something that works,
below is the code. It probably isn't the most elegant solution but it does
what it needs to do. There is still some error checking to be done and some
other functionality to be put in. I don't know if this is the best solution
for I'm pretty much a hack at C++ programming. Is there any documentation
that is geared more toward VC++ than VB?. There really is a lack of API
documentation for VC++ programers.

Thanks
Josh

CComPtr pDoc;
CComPtr pPartCompDef;
CComPtr pHolePoints;

// Getting the active document.
HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
if (FAILED(hr))
{
AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
return hr;
}

// Checking document type.
DocumentTypeEnum docType;
pDoc->get_DocumentType(&docType);

// Is the active document a part document.
if(docType == kPartDocumentObject)
{
// pPartDoc is defined in header file and is defined as
CComQIPtr pPartDoc;
pPartDoc = pDoc;

// Getting component definition.
hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
if(FAILED(hr))
{
AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
return hr;
}
}
else if (docType == kAssemblyDocumentObject)
{
// Getting assembly document
CComQIPtr pAssyDoc(pDoc);
CComPtr pObject;

// Getting part document
hr = pAssyDoc->get_ActivatedObject(&pObject);

pPartDoc = pObject;

DocumentTypeEnum assyDocType;
pPartDoc->get_DocumentType(&assyDocType);

// Checking document type and making sure it is a part
if(assyDocType == kPartDocumentObject)
{
// Getting component definition
hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
if(FAILED(hr))
{
AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
return hr;
}
}
}

// Get selection and add holes.
// This function iterates through the sketch and get all the hole points.
hr = selPoints(pHolePoints);
if(FAILED(hr)) return hr;

// Returning from sketch
// Getting the object.
CComPtr pObject;
hr = pPartDoc->get_ActivatedObject(&pObject);
if (FAILED(hr)) return hr;

// Checking for an active sketch
if(pPartDoc->SketchActive)
{
CComQIPtr pSketch(pObject);

// Close the sketch.
hr = pSketch->ExitEdit();
if (FAILED(hr)) return hr;
}
}

"Brian Ekins (Autodesk)" wrote in message
news:0C651197A67B39AF40D6D9120D5E809A@in.WebX.maYIadrTaRb...
> Josh,
>
> This was an interesting problem. Below is some code that I think does
what
> you want. I ran into one issue with Inventor not returning from the
sketch
> environment after creating the feature. I've logged a defect for this but
> was also able to workaround it by calling the "Return" command explicitly.
>
> Public Sub CreateHoles()
> ' Check to see that a sketch is the active edit object.
> Dim oSketch As PlanarSketch
> If TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
> ' Check to see that the sketch is in a part document and not an
> assembly.
> ' This is because assembly features are not currently supported.
> If TypeOf ThisApplication.ActiveEditObject.Parent Is
> PartComponentDefinition Then
> Set oSketch = ThisApplication.ActiveEditObject
> Else
> MsgBox "A part sketch with hole centers must be active."
> Exit Sub
> End If
> ElseIf TypeOf ThisApplication.ActiveEditObject Is PartDocument Then
> Dim oPartDoc As PartDocument
> Set oPartDoc = ThisApplication.ActiveEditObject
> If TypeOf oPartDoc.ActivatedObject Is PlanarSketch Then
> Set oSketch = oPartDoc.ActivatedObject
> Else
> MsgBox "A part sketch with hole centers must be active."
> Exit Sub
> End If
> Else
> MsgBox "A part sketch with hole centers must be active."
> Exit Sub
> End If
>
>
> ' Find all of the hole centers on the sketch and add them to the
> collection.
> Dim oHoleCenters As ObjectCollection
> Set oHoleCenters =
> ThisApplication.TransientObjects.CreateObjectCollection
>
> Dim oPoint As SketchPoint
> For Each oPoint In oSketch.SketchPoints
> If oPoint.HoleCenter Then
> oHoleCenters.Add oPoint
> End If
> Next
>
> ' Create the hole feature.
> Dim oPartCompDef As PartComponentDefinition
> Set oPartCompDef = oSketch.Parent
> Call
>
oPartCompDef.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenters,
> 2, 2, kPositiveExtentDirection)
>
> ' When editing a part in-place within an assembly, it's not correctly
> ' exiting the sketch environment when the feature is created. This
> ' forces the exit.
> If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
> ThisApplication.CommandManager.[_StartCommand] 44011
> End If
> End Sub
>
> -Brian
>
> "Josh Tiffin" wrote in message
> news:E214B43F7DDE923EB16DA791CE50CE7B@in.WebX.maYIadrTaRb...
> > What I'm trying to do is make a program that will insert our company's
> > standard hole sizes nto a part or into an edited part in an assembly
file.
> > Some background info on how it should work. The user puts a sketch on a
> > plane or planar surface and draws hole points where they want. They run
> the
> > hole program and the program iterates through tht open sketch finds the
> hole
> > points and adds the holes and closes the sketch. The code I have below
> > works fine for a part file, but when I am editing a part in an assembly
> > file, as soon as I try to get the selectset or anything else from the
> edited
> > part it crashes. I have checked the enumeration value of the of the
> > document type object in both cases and they both return
> > kPartDocumentObject. The program seems to fail in the selPoints
function
> > where I check if the user has selected anything and add the hole points
to
> > an object collection. My main question is has anybody done something
> > similar either in VB or in VC++ and got it to work for both a single
part
> > and a part in an assembly? Any help would be appreciated
> >
> > Josh
> >
> > // Getting the active document.
> > CComPtr pDoc;
> > CComQIPtr pAssyDoc;
> > CComQIPtr pPartCompDef;
> > CComPtr pHolePoints;
> >
> > HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
> > if (FAILED(hr))
> > {
> > AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
> > return hr;
> > }
> >
> > // Checking document type.
> > DocumentTypeEnum docType;
> > pDoc->get_DocumentType(&docType);
> >
> > // Is the active document a part document.
> > if(docType == kPartDocumentObject)
> > {
> > pPartDoc = pDoc;
> >
> > // Getting component definition.
> > hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
> > if(FAILED(hr))
> > {
> > AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> > return hr;
> > }
> > }
> > else if (docType == kAssemblyDocumentObject)
> > {
> > CComPtr pAssyCompDef;
> > CComPtr pActiveOcc;
> >
> > pAssyDoc = pDoc;
> >
> > hr = pAssyDoc->get_ComponentDefinition(&pAssyCompDef);
> > if (FAILED(hr))
> > {
> > AfxMessageBox(_T("get_ComponentDefinition Failed!"));
> > return hr;
> > }
> >
> > hr = pAssyCompDef->get_ActiveOccurrence(&pActiveOcc);
> > if (FAILED(hr))
> > {
> > AfxMessageBox(_T("get_ActiveOccurrence Failed!"));
> > return hr;
> > }
> >
> > DocumentTypeEnum assyDocType;
> > pActiveOcc->get_DefinitionDocumentType(&assyDocType);
> >
> > if(assyDocType == kPartDocumentObject)
> > {
> >
> > // Getting component definition
> > CComPtr pCompDef;
> > hr = pActiveOcc->get_Definition(&pCompDef);
> > if(FAILED(hr))
> > {
> > AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> > return hr;
> > }
> >
> > pPartDoc = pActiveOcc;
> > pPartCompDef = pCompDef;
> >
> > }
> >
> > }
> >
> > // Get selection and add holes.
> > hr = selPoints(pHolePoints);
> > if(FAILED(hr)) return hr;
> >
> >
>
>
0 Likes
Message 4 of 4

Anonymous
Not applicable
There is a lot of documentation we still want to write. The intent is that
the overviews will use VBA, but we want to have a section on general
practices using C++ and how to perform certain operations using C++, such as
using arrays, strings, events, etc.

-Brian

"Josh Tiffin" wrote in message
news:1487C70E2575A4E34F00F01125EE87D5@in.WebX.maYIadrTaRb...
> Brian
>
> Thanks for the response. I managed to put together something that works,
> below is the code. It probably isn't the most elegant solution but it
does
> what it needs to do. There is still some error checking to be done and
some
> other functionality to be put in. I don't know if this is the best
solution
> for I'm pretty much a hack at C++ programming. Is there any documentation
> that is geared more toward VC++ than VB?. There really is a lack of API
> documentation for VC++ programers.
>
> Thanks
> Josh
>
> CComPtr pDoc;
> CComPtr pPartCompDef;
> CComPtr pHolePoints;
>
> // Getting the active document.
> HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
> if (FAILED(hr))
> {
> AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
> return hr;
> }
>
> // Checking document type.
> DocumentTypeEnum docType;
> pDoc->get_DocumentType(&docType);
>
> // Is the active document a part document.
> if(docType == kPartDocumentObject)
> {
> // pPartDoc is defined in header file and is defined as
> CComQIPtr pPartDoc;
> pPartDoc = pDoc;
>
> // Getting component definition.
> hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
> if(FAILED(hr))
> {
> AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> return hr;
> }
> }
> else if (docType == kAssemblyDocumentObject)
> {
> // Getting assembly document
> CComQIPtr pAssyDoc(pDoc);
> CComPtr pObject;
>
> // Getting part document
> hr = pAssyDoc->get_ActivatedObject(&pObject);
>
> pPartDoc = pObject;
>
> DocumentTypeEnum assyDocType;
> pPartDoc->get_DocumentType(&assyDocType);
>
> // Checking document type and making sure it is a part
> if(assyDocType == kPartDocumentObject)
> {
> // Getting component definition
> hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
> if(FAILED(hr))
> {
> AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> return hr;
> }
> }
> }
>
> // Get selection and add holes.
> // This function iterates through the sketch and get all the hole
points.
> hr = selPoints(pHolePoints);
> if(FAILED(hr)) return hr;
>
> // Returning from sketch
> // Getting the object.
> CComPtr pObject;
> hr = pPartDoc->get_ActivatedObject(&pObject);
> if (FAILED(hr)) return hr;
>
> // Checking for an active sketch
> if(pPartDoc->SketchActive)
> {
> CComQIPtr pSketch(pObject);
>
> // Close the sketch.
> hr = pSketch->ExitEdit();
> if (FAILED(hr)) return hr;
> }
> }
>
> "Brian Ekins (Autodesk)" wrote in message
> news:0C651197A67B39AF40D6D9120D5E809A@in.WebX.maYIadrTaRb...
> > Josh,
> >
> > This was an interesting problem. Below is some code that I think does
> what
> > you want. I ran into one issue with Inventor not returning from the
> sketch
> > environment after creating the feature. I've logged a defect for this
but
> > was also able to workaround it by calling the "Return" command
explicitly.
> >
> > Public Sub CreateHoles()
> > ' Check to see that a sketch is the active edit object.
> > Dim oSketch As PlanarSketch
> > If TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
> > ' Check to see that the sketch is in a part document and not an
> > assembly.
> > ' This is because assembly features are not currently supported.
> > If TypeOf ThisApplication.ActiveEditObject.Parent Is
> > PartComponentDefinition Then
> > Set oSketch = ThisApplication.ActiveEditObject
> > Else
> > MsgBox "A part sketch with hole centers must be active."
> > Exit Sub
> > End If
> > ElseIf TypeOf ThisApplication.ActiveEditObject Is PartDocument Then
> > Dim oPartDoc As PartDocument
> > Set oPartDoc = ThisApplication.ActiveEditObject
> > If TypeOf oPartDoc.ActivatedObject Is PlanarSketch Then
> > Set oSketch = oPartDoc.ActivatedObject
> > Else
> > MsgBox "A part sketch with hole centers must be active."
> > Exit Sub
> > End If
> > Else
> > MsgBox "A part sketch with hole centers must be active."
> > Exit Sub
> > End If
> >
> >
> > ' Find all of the hole centers on the sketch and add them to the
> > collection.
> > Dim oHoleCenters As ObjectCollection
> > Set oHoleCenters =
> > ThisApplication.TransientObjects.CreateObjectCollection
> >
> > Dim oPoint As SketchPoint
> > For Each oPoint In oSketch.SketchPoints
> > If oPoint.HoleCenter Then
> > oHoleCenters.Add oPoint
> > End If
> > Next
> >
> > ' Create the hole feature.
> > Dim oPartCompDef As PartComponentDefinition
> > Set oPartCompDef = oSketch.Parent
> > Call
> >
>
oPartCompDef.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenters,
> > 2, 2, kPositiveExtentDirection)
> >
> > ' When editing a part in-place within an assembly, it's not
correctly
> > ' exiting the sketch environment when the feature is created. This
> > ' forces the exit.
> > If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
> > ThisApplication.CommandManager.[_StartCommand] 44011
> > End If
> > End Sub
> >
> > -Brian
> >
> > "Josh Tiffin" wrote in message
> > news:E214B43F7DDE923EB16DA791CE50CE7B@in.WebX.maYIadrTaRb...
> > > What I'm trying to do is make a program that will insert our company's
> > > standard hole sizes nto a part or into an edited part in an assembly
> file.
> > > Some background info on how it should work. The user puts a sketch on
a
> > > plane or planar surface and draws hole points where they want. They
run
> > the
> > > hole program and the program iterates through tht open sketch finds
the
> > hole
> > > points and adds the holes and closes the sketch. The code I have
below
> > > works fine for a part file, but when I am editing a part in an
assembly
> > > file, as soon as I try to get the selectset or anything else from the
> > edited
> > > part it crashes. I have checked the enumeration value of the of the
> > > document type object in both cases and they both return
> > > kPartDocumentObject. The program seems to fail in the selPoints
> function
> > > where I check if the user has selected anything and add the hole
points
> to
> > > an object collection. My main question is has anybody done something
> > > similar either in VB or in VC++ and got it to work for both a single
> part
> > > and a part in an assembly? Any help would be appreciated
> > >
> > > Josh
> > >
> > > // Getting the active document.
> > > CComPtr pDoc;
> > > CComQIPtr pAssyDoc;
> > > CComQIPtr pPartCompDef;
> > > CComPtr pHolePoints;
> > >
> > > HRESULT hr = m_pApplication->get_ActiveDocument(&pDoc);
> > > if (FAILED(hr))
> > > {
> > > AfxMessageBox(_T("m_pApplication->get_ActiveDocument Failed!"));
> > > return hr;
> > > }
> > >
> > > // Checking document type.
> > > DocumentTypeEnum docType;
> > > pDoc->get_DocumentType(&docType);
> > >
> > > // Is the active document a part document.
> > > if(docType == kPartDocumentObject)
> > > {
> > > pPartDoc = pDoc;
> > >
> > > // Getting component definition.
> > > hr = pPartDoc->get_ComponentDefinition(&pPartCompDef);
> > > if(FAILED(hr))
> > > {
> > > AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> > > return hr;
> > > }
> > > }
> > > else if (docType == kAssemblyDocumentObject)
> > > {
> > > CComPtr pAssyCompDef;
> > > CComPtr pActiveOcc;
> > >
> > > pAssyDoc = pDoc;
> > >
> > > hr = pAssyDoc->get_ComponentDefinition(&pAssyCompDef);
> > > if (FAILED(hr))
> > > {
> > > AfxMessageBox(_T("get_ComponentDefinition Failed!"));
> > > return hr;
> > > }
> > >
> > > hr = pAssyCompDef->get_ActiveOccurrence(&pActiveOcc);
> > > if (FAILED(hr))
> > > {
> > > AfxMessageBox(_T("get_ActiveOccurrence Failed!"));
> > > return hr;
> > > }
> > >
> > > DocumentTypeEnum assyDocType;
> > > pActiveOcc->get_DefinitionDocumentType(&assyDocType);
> > >
> > > if(assyDocType == kPartDocumentObject)
> > > {
> > >
> > > // Getting component definition
> > > CComPtr pCompDef;
> > > hr = pActiveOcc->get_Definition(&pCompDef);
> > > if(FAILED(hr))
> > > {
> > > AfxMessageBox(_T("pPartDoc->get_ComponentDefinition Failed!"));
> > > return hr;
> > > }
> > >
> > > pPartDoc = pActiveOcc;
> > > pPartCompDef = pCompDef;
> > >
> > > }
> > >
> > > }
> > >
> > > // Get selection and add holes.
> > > hr = selPoints(pHolePoints);
> > > if(FAILED(hr)) return hr;
> > >
> > >
> >
> >
>
>
0 Likes