using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Diagnostics;
using
SolidWorks.Interop.swdocumentmgr;
namespace
GetExtRef_CSharp
{
class
Program
{
static
SwDMClassFactory
dmClassFact;
static
SwDMApplication3
dmDocMgr;
static
SwDMDocument15
dmDoc;
static
SwDmDocumentType
dmDocType;
static
SwDMSearchOption
dmSearchOpt;
static
SwDmDocumentOpenError
status;
static
SwDMExternalReferenceOption
dmExtRefOption;
static
int
numExtRefs;
static
SwDmXmlDataError xmlError;
const
string
docPath = "<SolidWorks_install_dir>\\samples\\tutorial\api\\assembly-with-mirrored-component.sldasm";
const
string
licenseKey = "<your_license_code>";
static
void
Main()
{
setDocType();
dmClassFact = new
SwDMClassFactory();
dmDocMgr = (SwDMApplication3)dmClassFact.GetApplication(licenseKey);
dmDoc = (SwDMDocument15)dmDocMgr.GetDocument(docPath,
dmDocType, true,
out
status);
if
((dmDoc != null))
{
NewMethod();
dmDoc.GetXmlStream("c:\\temp\\extRef.xml",
ref xmlError);
dmDoc.CloseDoc();
}
else
{
Debug.Print("Unable
to open document. Check 'docPath' variable path.");
}
}
public
static
void
NewMethod()
{
dmExtRefOption = dmDocMgr.GetExternalReferenceOptionObject();
dmSearchOpt = dmDocMgr.GetSearchOptionObject();
dmExtRefOption.SearchOption = dmSearchOpt;
dmExtRefOption.Configuration = "Default";
dmExtRefOption.NeedSuppress = true;
numExtRefs = dmDoc.GetExternalFeatureReferences(ref
dmExtRefOption);
PrintStrings("FilePath",
dmExtRefOption.ExternalReferences);
PrintStrings("ConfigName",
dmExtRefOption.ReferencedConfigurations);
dmSearchOpt = null;
dmExtRefOption = null;
}
public
static
void
setDocType()
{
string
typeStr = null;
typeStr = docPath.Substring((docPath.Length - 6),6);
typeStr = typeStr.ToUpper();
if
((typeStr == "SLDPRT"))
{
dmDocType =
SwDmDocumentType.swDmDocumentPart;
}
else
if ((typeStr
== "SLDASM"))
{
dmDocType =
SwDmDocumentType.swDmDocumentAssembly;
}
}
public
static
void
PrintStrings(string
name, object
varInp)
{
int
I = 0;
String[]
arrInp;
arrInp = (String[])varInp;
for
(I = 0; I < arrInp.Length; I++)
{
string
str = null;
str = arrInp[I];
Debug.Print(name
+ " : "
+ str);
}
}
}
}