26 #include "smartvars.h"
54 WideString acstostr(file);
55 BSTR filename=BSTR(acstostr);
56 WideString acstostr2(
"");
57 BSTR configuration=BSTR(acstostr2);
66 swApp->OpenDoc6(filename, type, options, configuration, &Errors, &Warnings, &
swModel);
81 hr = __swFace->GetTessTriangleCount(__triangleCount);
82 if (hr != S_OK)
return;
84 CComVariant vTessTriang;
85 hr = __swFace->GetTessTriangles(VARIANT_TRUE, &vTessTriang);
86 if (hr != S_OK)
return;
87 SafeFloatArray saTessPts (vTessTriang);
89 unsigned long nbCoords = *__triangleCount*9;
90 *__tessPts =
new double [nbCoords];
92 for (
unsigned i=0; i < nbCoords; i++)
94 (*__tessPts)[i] = saTessPts[i];
112 iswToleranceID = swBSCurveOutputTol;
115 iswToleranceID = swBSCurveNonRationalOutputTol;
118 iswToleranceID = swUVCurveOutputTol;
121 iswToleranceID = swSurfChordTessellationTol;
124 iswToleranceID = swSurfAngularTessellationTol;
127 iswToleranceID = swCurveChordTessellationTol;
132 CComPtr<IModeler> swModeler;
133 swApp->IGetModeler(&swModeler);
135 swModeler->SetToleranceValue(iswToleranceID,__tolerance);
145 WideString acstostr(file);
146 BSTR nom=BSTR(acstostr);
147 swModel->SaveAs4 ( nom, swSaveAsCurrentVersion, swSaveAsOptions_SaveReferenced , &Errors, &Warnings ,&retval);
161 swApp.CoCreateInstance(CLSID_SldWorks_, NULL, CLSCTX_LOCAL_SERVER);
191 CComQIPtr <IPartDoc> swPart;
193 CComVariant vBodyArr;
194 swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
195 SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
196 LPDISPATCH* pBodyDispArray = NULL;
197 long nBodyHighIndex = -1;
198 long nBodyCount = -1;
199 SafeArrayAccessData(psaBody, (
void **) &pBodyDispArray);
200 SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
201 nBodyCount = nBodyHighIndex + 1;
202 for (
int i = 0; i < nBodyCount; i++)
204 CComQIPtr <IBody2> pBody;
205 pBody = pBodyDispArray[i];
206 CComPtr <IFace2> face;
207 CComPtr <IFace2> suivantface;
208 CComPtr <ISurface> surf;
210 pBody->GetFaceCount(&nbFaces);
211 pBody->IGetFirstFace(&face);
213 for (
int f=0;
f<nbFaces;
f++)
216 CComPtr <ILoop2> loope;
217 CComPtr <ILoop2> nextloope;
218 face->IGetFirstLoop(&loope);
220 face->GetLoopCount(&nbloop);
221 for (
int l = 0;l<nbloop;l++)
224 CComPtr <ICoEdge> Coarete;
225 CComPtr <ICoEdge> nextCoarete;
226 loope->IGetFirstCoEdge(&Coarete);
228 loope->GetEdgeCount(&nbCoarete);
229 for (
int coa=0;coa<nbCoarete;coa++)
231 CComPtr <IEdge> arete;
232 Coarete->IGetEdge(&arete);
234 CComPtr <IVertex> Sommet1;
235 arete->IGetStartVertex(&Sommet1);
240 CComPtr <IVertex> Sommet2;
241 arete->IGetEndVertex(&Sommet2);
247 Coarete->IGetNext(&nextCoarete);
248 Coarete = nextCoarete;
249 nextCoarete.Release();
252 loope->IGetNext(&nextloope);
258 face->IGetNextFace(&suivantface);
260 suivantface.Release();
284 CComQIPtr <IPartDoc> swPart;
287 CComPtr <IEntity> entite;
289 swPart->GetNamedEntitiesCount ( &count );
293 CComVariant vBodyArr;
294 swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
295 SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
296 LPDISPATCH* pBodyDispArray = NULL;
297 long nBodyHighIndex = -1;
298 long nBodyCount = -1;
299 SafeArrayAccessData(psaBody, (
void **) &pBodyDispArray);
300 SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
301 nBodyCount = nBodyHighIndex + 1;
303 for (
int i = 0; i < nBodyCount; i++)
305 CComQIPtr <IBody2> pBody;
306 pBody = pBodyDispArray[i];
307 CComPtr <IFace2> face;
308 CComPtr <IFace2> suivantface;
309 CComPtr <ISurface> surf;
311 pBody->GetFaceCount(&nbFaces);
312 pBody->IGetFirstFace(&face);
314 for (
int f=0;
f<nbFaces;
f++)
318 CComPtr <ILoop2> loope;
319 CComPtr <ILoop2> nextloope;
320 face->IGetFirstLoop(&loope);
322 face->GetLoopCount(&nbloop);
323 for (
int l = 0;l<nbloop;l++)
326 CComPtr <ICoEdge> Coarete;
327 CComPtr <ICoEdge> nextCoarete;
328 loope->IGetFirstCoEdge(&Coarete);
330 loope->GetEdgeCount(&nbCoarete);
331 for (
int coa=0;coa<nbCoarete;coa++)
334 CComPtr <IEdge> arete;
335 Coarete->IGetEdge(&arete);
339 CComPtr <IVertex> Sommet1;
340 arete->IGetStartVertex(&Sommet1);
345 CComPtr <IVertex> Sommet2;
346 arete->IGetEndVertex(&Sommet2);
354 Coarete->IGetNext(&nextCoarete);
355 Coarete = nextCoarete;
356 nextCoarete.Release();
361 loope->IGetNext(&nextloope);
367 face->IGetNextFace(&suivantface);
369 suivantface.Release();
383 CComPtr <IEntity> ent;
384 WideString acstostr(ID);
385 BSTR nom=BSTR(acstostr);
386 CComQIPtr <IPartDoc> swPart;
388 swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
394 ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
401 CComPtr <IEntity> ent;
402 CComQIPtr <IPartDoc> swPart;
404 swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
410 ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
417 CComPtr <IEntity> ent;
418 WideString acstostr(ID);
419 BSTR nom=BSTR(acstostr);
420 CComQIPtr <IPartDoc> swPart;
422 swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
462 CComPtr <IFeature> swFeat;
463 CComPtr <IFeature> swNextFeat;
464 VARIANT_BOOL bSupprime;
467 CComPtr <IEntity> ent;
469 swPart->IFirstFeature(&swFeat);
472 swFeat->IsSuppressed(&bSupprime);
476 swFeat->GetTypeName(&NomFeat);
478 CComBSTR Compo1 (
"CompositeCurve.");
479 CComBSTR Compo2 (
"3DSplineCurve.");
481 if ((Compo1==NomFeat) || (Compo2==NomFeat))
483 CComPtr <IReferenceCurve> refCourbe;
484 CComPtr <IUnknown> Unk;
486 swFeat->IGetSpecificFeature(&Unk);
487 Unk->QueryInterface( IID_IReferenceCurve, (LPVOID*)&refCourbe);
489 CComPtr<IEdge> swArete;
490 refCourbe->IGetFirstSegment(&swArete);
495 sprintf(id3,
"%s",
GetID(swArete.p).c_str());
496 if (strcmp(ID, id3)==0 )
502 refCourbe->IGetNextSegment(&swArete);
507 swFeat->IGetNextFeature(&swNextFeat);
509 swNextFeat.Release();
519 ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
531 CComPtr <IEntity> ent;
532 CComQIPtr <IPartDoc> swPart;
534 swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
540 ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
546 CComPtr <IEntity> ent;
547 WideString acstostr(ID);
548 BSTR nom=BSTR(acstostr);
549 CComQIPtr <IPartDoc> swPart;
551 swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
554 printf(
"Failed to get %s\n", ID);
558 ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
564 CComPtr <IEntity> ent;
565 CComQIPtr <IPartDoc> swPart;
567 swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
573 ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
579 CComPtr<IFace2> face;
581 face->IGetSurface(&surface);
587 CComPtr<IEdge> arete;
589 arete->IGetCurve(&courbe);
599 static long compteur=1;
600 CComPtr <IEntity> ent;
608 strcpy(nom2,
"Face_Libre");
611 _ltoa(compteur,nom3,10);
614 WideString acstostr(nom2);
615 BSTR nom=BSTR(acstostr);
617 face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
618 CComQIPtr <IPartDoc> swPart;
620 swPart->ISetEntityName( ent, nom , &retval );
621 if (retval!=0) compteur++;
628 CComPtr <IEntity> ent;
630 face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
631 CComQIPtr <IPartDoc> swPart;
633 swPart->DeleteEntityName ( ent, &retval );
641 static long compteur=1;
642 CComPtr <IEntity> ent;
648 strcpy(nom2,
"Arete");
650 strcpy(nom2,
"Arete_Coque");
652 strcpy(nom2,
"Arete_Poutre");
655 _ltoa(compteur,nom3,10);
658 WideString acstostr(nom2);
659 BSTR nom=BSTR(acstostr);
661 arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
662 CComQIPtr <IPartDoc> swPart;
664 swPart->ISetEntityName( ent, nom , &retval );
666 if (retval!=0) compteur++;
674 CComPtr <IEntity> ent;
676 arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
677 CComQIPtr <IPartDoc> swPart;
679 swPart->DeleteEntityName ( ent, &retval );
687 static long compteur=1;
688 CComPtr <IEntity> ent;
694 strcpy(nom2,
"Sommet");
696 strcpy(nom2,
"Sommet_Coque");
698 strcpy(nom2,
"Sommet_Poutre");
701 _ltoa(compteur,nom3,10);
704 WideString acstostr(nom2);
705 BSTR nom=BSTR(acstostr);
707 sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
708 CComQIPtr <IPartDoc> swPart;
710 swPart->ISetEntityName( ent, nom , &retval );
712 if (retval!=0) compteur++;
718 CComPtr <IEntity> ent;
720 sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
721 CComQIPtr <IPartDoc> swPart;
723 swPart->DeleteEntityName ( ent, &retval );
731 CComPtr <IEntity> ent;
732 CComPtr <IEdge> swarete(arete);
733 swarete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
736 swModel->IGetEntityName ( ent, &retval );
739 CComPtr <IAttribute> Attribut;
743 IParameter* parammaitre;
744 CComBSTR nomParam(
"Maitre.") ;
745 Attribut->IGetParameter ( nomParam, ¶mmaitre );
746 parammaitre->GetStringValue(&retval) ;
749 IParameter* paramsens;
750 CComBSTR nomParam2(
"Sens.") ;
751 Attribut->IGetParameter ( nomParam2, ¶msens );
752 paramsens->GetDoubleValue(&sens2) ;
757 swModel->IGetEntityName ( ent, &retval );
760 AnsiString rep(retval);
768 CComPtr <IEntity> ent;
769 CComPtr <IFace2> swface(face);
771 swface->QueryInterface( IID_IEntity, (LPVOID*)&ent);
774 swModel->IGetEntityName ( ent, &retval );
776 AnsiString rep(retval);
784 CComPtr <IEntity> ent;
785 CComPtr<IVertex> swSommet(sommet);
786 swSommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
790 swModel->IGetEntityName ( ent, &retval );
792 CComPtr <IAttribute> Attribut;
796 IParameter* parammaitre;
797 CComBSTR nomParam(
"Maitre.") ;
798 Attribut->IGetParameter ( nomParam, ¶mmaitre );
799 parammaitre->GetStringValue(&retval) ;
803 swModel->IGetEntityName ( ent, &retval );
806 AnsiString rep(retval);
815 double petit = 999999999;
818 CComVariant vBodyArr;
819 CComQIPtr<IPartDoc> swPart;
821 swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
822 SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
823 LPDISPATCH* pBodyDispArray = NULL;
824 long nBodyHighIndex = -1;
825 SafeArrayAccessData(psaBody, (
void **) &pBodyDispArray);
826 SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
827 long nb_sld_corps = nBodyHighIndex + 1;
829 for (
long i=0;i<nb_sld_corps;i++)
831 CComQIPtr <IBody2> swBody;
832 swBody = pBodyDispArray[i];
835 vRetval=swBody->GetBodyBox();
836 SafeDoubleArray sda(vRetval);
844 actuelle =
sqrt( (coins[0] - coins[3])*(coins[0] - coins[3]) + (coins[1] - coins[4])*(coins[1] - coins[4]) + (coins[2] - coins[5])*(coins[2] - coins[5])) /10000000 ;
846 actuelle = std::max(actuelle, 1E-6);
847 if (actuelle <petit ) petit = actuelle;