Message 1 of 4
Accessing Sketch and Part Object In Assembly

Not applicable
04-01-2003
02:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
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
CComQIPtr
CComQIPtr
CComPtr
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
CComPtr
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
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;