.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[VB.Net] IntersectWith Surfaces Acad 2013 / 2014

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
AdriDicri
2123 Views, 5 Replies

[VB.Net] IntersectWith Surfaces Acad 2013 / 2014

Hello !

 

I'm currently using Autocad 2013, and I need to use the function intersectWith with 2 surfaces. The message i get is "Not yet implemented".


Can somebody tell me if this function is working in Autocad 2014?

 

Thanks in advance.

 

Adri DiCri.

 

5 REPLIES 5
Message 2 of 6
SEANT61
in reply to: AdriDicri

I suspect that a surface/surface compatible Entity.IntersectWith method is still some time away. 

 

The Autodesk.AutoCAD.Geometry.SurfaceSurfaceIntersector can be used but the database surfaces need to be translated.  That can be accomplished via    Autodesk.AutoCAD.BoundaryRepresentation.Face.GetSurfaceAsNurb Method.

 

 A fairly convoluted process to be sure, but quite possible.

 

Another possibility may be to thicken one of the surfaces into a solid, and Imprint the other surface onto that.  The pertinent face of that solid would need to be analyzed to return the resultant imprinted geometry.


************************************************************
May your cursor always snap to the location intended.
Message 3 of 6
AdriDicri
in reply to: SEANT61

Hello again !

 

I managed to have a result with the SurfaceSurfaceIntersector but (and don't laught) I can't retrieve the intersection points between my two surfaces.

 

Which method of SurfaceIntersector should I use to get my points?

 

I'm sure i should have a result, because the "NumResult" give me 1, so i guess it's correct?

 

 

'Brep surface 1
Using brep As New Brep(surf) Dim acFaceColl As BrepFaceCollection = brep.Faces For Each face2 As Autodesk.AutoCAD.BoundaryRepresentation.Face In acFaceColl
Dim sGeo As Autodesk.AutoCAD.Geometry.NurbSurface = face2.GetSurfaceAsNurb()

'other stuff For i As Integer = 0 To dbsurfaceFace3D.Count - 1
'other stuff intersectPoints.Clear() entFace3D = dbsurfaceFace3D(i)

'Brep surface 2 Using brep2 As New Brep(entFace3D) For Each face3 As Autodesk.AutoCAD.BoundaryRepresentation.Face In acFaceColl Dim sGeo2 As Autodesk.AutoCAD.Geometry.NurbSurface = face3.GetSurfaceAsNurb() ssi = New Autodesk.AutoCAD.Geometry.SurfaceSurfaceIntersector(sGeo2, sGeo)

'stuck here *********

Next End Using Next Next End Using

 

This code is not very nice, but it's just to make some tests 😉

 

Best regards, and best wishes for 2014 !

Message 4 of 6
SEANT61
in reply to: AdriDicri

I have a demo routine that, unfortunately, I do not have the time to translate.   Hopefully you can make use of the c# code.  The routine was used to create the attached example.

 

using System;

using System.Runtime.InteropServices;

using Autodesk.AutoCAD;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.BoundaryRepresentation;

 

 

 

[assembly: CommandClass(typeof(CsSurfIntersect.STSCCommands))]

namespace CsSurfIntersect

{

publicclassSTSCCommands

{

public STSCCommands()

{

}

[CommandMethod("SurfInt")]

staticpublicvoid SurfInt()

{

Database db = HostApplicationServices.WorkingDatabase;

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

ObjectId ObjID;

using (Transaction trans = db.TransactionManager.StartTransaction())

{

try

{

Autodesk.AutoCAD.DatabaseServices.Surface surf1;

Autodesk.AutoCAD.DatabaseServices.Surface surf2;

SurfGeomConstruct sgc1;

SurfGeomConstruct sgc2;

PromptEntityOptions peo = newPromptEntityOptions("Select first surface for intersection: ");

peo.SetRejectMessage("\nPlease select only a Surface");

peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Surface), false);

PromptEntityResult per = ed.GetEntity(peo);

if (per.Status != PromptStatus.OK) return;

ObjID = per.ObjectId;

surf1 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false);

surf1.Highlight();

peo.Message = "Select intersecting surface: ";

per = ed.GetEntity(peo);

if (per.Status != PromptStatus.OK) return;

surf1.Unhighlight();

sgc1 = newSurfGeomConstruct(surf1);

 

ObjID = per.ObjectId;

surf2 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false);

sgc2 = newSurfGeomConstruct(surf2);

SurfaceSurfaceIntersector ssi = newSurfaceSurfaceIntersector();

ssi.Set(sgc1.GeomSurf, sgc2.GeomSurf);

int count = ssi.NumResults;

if (count < 1) return;

BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));

for (int i = 0; i < count; i++)

{

Curve3d c3d = ssi.IntersectCurve(i, true);

Curve crv = GenCurve(c3d);

crv.SetDatabaseDefaults();

btr.AppendEntity(crv);

trans.AddNewlyCreatedDBObject(crv, true);

}

if (ssi != null) ssi.Dispose();

if (sgc1.GeomSurf != null) sgc1.GeomSurf.Dispose();

if (sgc2.GeomSurf != null) sgc2.GeomSurf.Dispose();

}

catch (System.Exception ex)

{

ed.WriteMessage("Error: " + ex.Message);

}

finally

{

trans.Commit();

}

}

}

 

//Internal

staticprivateCurve GenCurve(Curve3d crv3d)

{

Tolerance tol = newTolerance();

ExternalCurve3d extCrv = crv3d asExternalCurve3d;

Line3d ln3d;

if (extCrv.IsLinear(out ln3d))

{

Line ln = newLine(crv3d.StartPoint, crv3d.EndPoint);

return ln;

}

else

{

Double per;

KnotCollection kc;

NurbCurve3d nc3d = extCrv.NativeCurve asNurbCurve3d;

kc = nc3d.Knots;

Double[] dblKnots = newDouble[kc.Count];

kc.CopyTo(dblKnots, 0);

DoubleCollection dc = newDoubleCollection(dblKnots);

NurbCurve3dData nc3dData = nc3d.DefinitionData;

returnnewSpline(nc3d.Degree, nc3d.IsRational, nc3d.IsClosed(), nc3d.IsPeriodic(out per),

nc3dData.ControlPoints, dc, nc3dData.Weights, tol.EqualPoint, tol.EqualVector);

}

}

 

}

classSurfGeomConstruct

{

private Autodesk.AutoCAD.Geometry.Surface m_geomSurf;

//Constructors

public SurfGeomConstruct(Autodesk.AutoCAD.DatabaseServices.Surface Surf)

{

GeomSurfGenerator(Surf);

}

//Properties

public Autodesk.AutoCAD.Geometry.Surface GeomSurf

{

get { return m_geomSurf; }

}

//Methods

privatevoid GeomSurfGenerator(Autodesk.AutoCAD.DatabaseServices.Surface Surf)

{

Brep Br = newBrep(Surf);

foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc in Br.Faces)

{

ExternalBoundedSurface[] ebSurfs = fc.GetSurfaceAsTrimmedNurbs();

m_geomSurf = ebSurfs[0];

}

Br.Dispose();

}

}

}

 

 


************************************************************
May your cursor always snap to the location intended.
Message 5 of 6
SEANT61
in reply to: SEANT61

****, formatting was quite botched above.  Maybe the attached will read better.


************************************************************
May your cursor always snap to the location intended.
Message 6 of 6
AdriDicri
in reply to: AdriDicri

Great ! Thanks a lot !

 

Adri DiCri

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost