Page 1 of 1

Lofting a surface from ICircle_DG

Posted: Tue Mar 04, 2025 4:19 pm
by Measure
Hello,

I am most likely doing something wrong here. I am generating some circles and trying to loft a surface from one circle to the other into a tube like geometry. When I call Build from IWireArrayToSurfaceBuilder_DG, the entire IDE or program crashes (maybe this needs better error handling).

I think the issue is converting the Icircle_DG (which is GetGeometryType says is Brep) to a IBrepWire_DG.

Can you tell me what I might be doing wrong? 32-bit VB6 code below (note, kcad control is called MyKernelCAD):

Code: Select all

'Kernel CAD session
Public MyModel3D As IModel_DG
Public MyObjGen3D As IObjectGenerator_DG
Public MyView3D As IView_DG

Private Sub CreateOpenCylinder()
    ' high-level object creation
    Set MyModel3D = MyKernelCAD.GetModel()
    Set MyView3D = MyKernelCAD.GetView()
    Set MyObjGen3D = MyModel3D

    'Declarations for final entity and shape builder
    Dim cylinder As IEntity_DG
    Dim Builder As IStdShape_DG
    Set Builder = MyObjGen3D.Create("IStdShape_DG")
    
    'Declarations for circles
    Dim crvCircle1 As IEntity_DG, crvCircle2 As IEntity_DG
    Dim wirCircle1 As IBRepWire_DG, wirCircle2 As IBRepWire_DG
    
    'Create circular curves
    Set crvCircle1 = Builder.Circle(8)
    Set crvCircle2 = Builder.Circle(8)
    Call crvCircle2.GetLocation.Translate1(0, 0, 10)
    
    'Display circles for debugging
    Call MyModel3D.AddEntity(crvCircle1)
    Call MyModel3D.AddEntity(crvCircle2)

    'Cast circles as wires by adding the curve as a Brep edge
    Set wirCircle1 = MyObjGen3D.Create("IBRepWire_DG")
    Set wirCircle2 = MyObjGen3D.Create("IBRepWire_DG")
    'Below does not seem to actually be adding the circle, GetEdgeCount = 0 and GetVertexCount = 0
    Call wirCircle1.AddEdge(crvCircle1)
    Call wirCircle2.AddEdge(crvCircle2)


    ' Add shape to the displayed model
    Dim SurfaceBuilder As IWireArrayToSurfaceBuilder_DG
    Set SurfaceBuilder = MyObjGen3D.Create("IWireArrayToSurfaceBuilder_DG")
    Call SurfaceBuilder.Init(False, 0.001)
    Call SurfaceBuilder.AddWire(wirCircle1)
    Call SurfaceBuilder.AddWire(wirCircle2)
   
    
    'This causes DGKernel to crash
    'Dim MyLoftedSurface As IBRepShape_DG
    'Set MyLoftedSurface = SurfaceBuilder.Build(False)
    'Set cylinder = MyLoftedSurface
    'Call MyModel3D.AddEntity(cylinder)
    
    ' Update the view
    Call MyView3D.Update
End Sub

Also please note, there is a total IDE crash if you try to access a IBRepWire_DG . GetEdge( index) and index is out of bounds. I think maybe some better error handling needed here too.

Thanks for all your support and assistance,

Adam

Re: Lofting a surface from ICircle_DG

Posted: Tue Mar 04, 2025 11:11 pm
by Measure
I know that most of this is how I am using the classes and probably how my code deviates from the VC samples when working with VB6 32bit com.

I was able to figure it out, how to loft from ICircle_DG.

Process was:
0) Create a new entity with iModel_DG AddNewBRepShape(eShTypeFaceDG)
1) Created a Brep Shape, added child Edges and Wires for each circle I wanted to loft using AddNewChildBRepShape
2) Built the circle using Icircle_DG
3) Set the circle to each edge with SetCurve
4) Set the edge to each wire with AddEdge
5) Called AddWire for each with a IWireArraySurfaceBuilder.
6) Successfully set the IBrepShape_DG from the build command of IWireArraySurfaceBuilder
7) Added the IBrepShape_DG to the entity with AddChildBRepShape
8) Add the entity to the iModel with AddEntity.

What I couldn't figure out...
Why does the entity in step 0 need to be declared with AddNewBRepShape(eShTypeFaceDG)?
Why is it type Face and not a Type Shape?

I couldn't seem to get it to work without using entity = AddNewBRepShape(eShTypeFaceDG) or by initializing the variable as a Face or even as a Shape with ObjectGenerator...

I am sure there is an easier way to create standalone wires from ICircle that work with IWireArraySurfaceBuilder without create a Brep shape, face, circles, edges, and wires?

And curious if I can do this without having to add something to the model, like do it as a standalone and then just add the resulting surface?

Appreciative of your hard work, for sure.

-Adam

Re: Lofting a surface from ICircle_DG

Posted: Thu Mar 06, 2025 12:57 am
by Mike Zubovic
The first observation:
In the installed Surfaces VB .NET sample
DGKernel_7_2\Samples\NET\VB\Modeling\Surfaces\SurfacesForm.vb the CreateSurface() does exactly that. It builds a pipe out of circles using IWireArrayToSurfaceBuilder_DG with different options.
The CreateWireCircle() builds a wire out of a circle.
All seems to be working.

Re: Lofting a surface from ICircle_DG

Posted: Thu Mar 06, 2025 1:08 am
by Mike Zubovic
The first problem I see is the

Code: Select all

'Below does not seem to actually be adding the circle, GetEdgeCount = 0 and GetVertexCount = 0
    Call wirCircle1.AddEdge(crvCircle1)
IBRepWire_DG.AddEdge(IBRepEdge_DG edge) expects an edge. You are calling with crvCircle1, which is an entity. VB must be trying to query IBRepEdge_DG out of crvCircle1. I would be very surprised if this works.

The easiest way is to copy the code out of .NET sample. It needs only minor changes to work with VB6

Re: Lofting a surface from ICircle_DG

Posted: Thu Mar 06, 2025 2:46 am
by Mike Zubovic
"I couldn't seem to get it to work without using entity = AddNewBRepShape(eShTypeFaceDG) or by initializing the variable as a Face or even as a Shape with ObjectGenerator..."

Sorry, Adam, your sequence does not make sense to me. I am sure you got it working. I do not believe it worth analyzing though. You have a good sample in Surfaces.

Re: Lofting a surface from ICircle_DG

Posted: Thu Mar 06, 2025 2:48 am
by Mike Zubovic
"And curious if I can do this without having to add something to the model, like do it as a standalone and then just add the resulting surface?"

Yes. It is what the sample does:

Code: Select all

Dim shape As IBRepShape_DG = iThruSections.Build(solid)
' Add shape to the displayed model
m_iModel.AddBRepShape(shape)
Regards