News:

Please remember to do a search before you ask a question!

Main Menu

VB Net draw a solid issue

Started by TedTheCarpenter, July 04, 2023, 11:04:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TedTheCarpenter

The code does create a solid but it's defective. Assigning a material does not work and exploding the solid crashes TC. Does anyone know how to properly create a solid (or TC Surface) using VB net? Thanks.grf = drw.Graphics.Add(, "TCW60ACISSOLID")
grf.Vertices.UseWorldCS = True
grf.Vertices.Add(0, 0, 0)
grf.Vertices.Add(48, 0, 0)
grf.Vertices.Add(48, 10, 0)
grf.Vertices.Add(0, 10, 0)
grf.Vertices.Add(0, 0, 0)
grf.Vertices.Add(0, 0, 1.5)
grf.Vertices.Add(48, 0, 1.5)
grf.Vertices.Add(48, 10, 1.5)
grf.Vertices.Add(0, 10, 1.5)
grf.Vertices.Add(0, 0, 1.5)
grf.Draw()
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

#1
I have never created an acis solid with a regen object.
This is the code from Kevin Chapmans surface example. (Sorry I don't have the project anymore)
You need to reference GXSurfaceLib.
Once you have the surface you can change the Solid property to convert it to solid, or smesh.

Kevins Example - note this takes a long time
 Dim gr As IMSIGX.Graphic
        gr = draw.Graphics.Add(IMSIGX.ImsiGraphicType.imsiSurface)

        'Connect to the surface's underlying data structure.
        Dim surf As GXSurfLib.ISurface
        surf = gr.Surface

        'Create the nodes that will define the surface.
        Dim nodes As GXSurfLib.Nodes
        nodes = surf.Nodes

        'Here we create the nodes for a 50-facet x 50-facet surface,
        'which requires 51x51 nodes. Since the array index starts at zero,
        'and the array is one-dimensional, we dimension the array to (51 * 51 - 1)
        'Note that creating the nodes is very fast.
        Dim i As Integer
        Dim j As Integer
        Dim inode As Integer
        Dim tempX As Double, tempY As Double, tempZ As Double
        ' The equation will calculate a surface whose X and Z coordinates
        ' range from -25 to 25, in steps of 0.2 units.
        ProgressLabel.Visible = True
        RowLabel.Visible = True
        ColumnLabel.Visible = True
        ProgressLabel.Text = "Creating Nodes"
        For i = 0 To 50
            tempZ = 0.2 * (i - 25)
            RowLabel.Text = "Row: " & i
            For j = 0 To 50
                tempX = 0.2 * (j - 25)
                ' The y-value is calculated from this equation:
                ' y = 0.25*x*x - 0.2*x*z -0.25*z*z
                tempY = 0.25 * tempX * tempX - 0.2 * tempX * tempZ - 0.25 * tempZ * tempZ
                inode = 51 * i + j 'calculates the node index for this point unnecessary
                nodes.Add(tempX, tempY, tempZ)
                ColumnLabel.Text = "Column: " & j
            Next
        Next

        'Next we generate facets from sets of nodes. This is a much slower process than
        'creating the nodes was.
        Dim facets As GXSurfLib.Facets
        facets = surf.Facets
        ProgressLabel.Text = "Creating Facets"
        Dim row0 As Integer, row1 As Integer, col0 As Integer, col1 As Integer
        Dim nodelist(3) As Integer
        For i = 0 To 49
            RowLabel.Text = "Row: " & i
            For j = 0 To 49
                row0 = 51 * i
                row1 = row0 + 51
                col0 = j
                col1 = j + 1
                nodelist(0) = row0 + col0
                nodelist(1) = row0 + col1
                nodelist(2) = row1 + col1
                nodelist(3) = row1 + col0
                surf.Facets.Add(nodelist) 'array of node indexes is used
                ColumnLabel.Text = "Column: " & j
            Next
        Next
        gr.Draw()


your cube using this method. I presume you know the easier methods to draw a cube via code.
I am sure my method can be simplified

  Dim grf As IMSIGX.Graphic = tcDraw.Graphics.Add(IMSIGX.ImsiGraphicType.imsiSurface)
        Dim surface As GXSurfLib.ISurface = grf.Surface
        Dim Nodes As GXSurfLib.Nodes = surface.Nodes
        With Nodes
            .Add(0, 0, 0)
            .Add(48, 0, 0)
            .Add(48, 10, 0)
            .Add(0, 10, 0)
            .Add(0, 0, 1.5)
            .Add(48, 0, 1.5)
            .Add(48, 10, 1.5)
            .Add(0, 10, 1.5)

        End With
        Dim facets As GXSurfLib.Facets = surface.Facets
        'Define  bottom face
        Dim nodelist(3) As Integer

        nodelist(0) = 0
            nodelist(1) = 1
            nodelist(2) = 2
            nodelist(3) = 3
            facets.Add(nodelist)
        '  first 3 side faces
        For i As Integer = 0 To 2
            nodelist(0) = i
            nodelist(1) = i + 1
            nodelist(2) = i + 5
            nodelist(3) = i + 4
            facets.Add(nodelist)
        Next
        ' 4th face
        nodelist(0) = 3
        nodelist(1) = 0
        nodelist(2) = 4
        nodelist(3) = 7
        facets.Add(nodelist)

        ' top face
        nodelist(0) = 4
        nodelist(1) = 5
        nodelist(2) = 6
        nodelist(3) = 7
        facets.Add(nodelist)
        'convert to solid
        grf.Properties.Item("Solid").Value = 1
        grf.Update()
        grf.Draw()




Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

Thanks for the reply Nikki but I've had no luck adding the reference to my project. I have TurboCAD versions on my computer going back to 2017 and a search for GXSurfLib or GXSurfaceLib or GXSurfLib.tlb or GXSurf.tlb yields nothing. I do have have GXSurf30.dll (I'm using TC 2023 Platinum) but Visual Studio tells me I cannot add it as a reference. I did add GXSurface 8.0 Type Library that was listed in the Reference Manager but that didn't work either.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

sorry its the GXsurf.dll file
found here
C:\Program Files\IMSIDesign\TCW2021\Program64\ImsigxExt
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

I don't have a GXsurf.dll in TCW2021. I do have GXsurf28.dll in TCW2021 and GXsurf30.dll in TCW2023. Both of them will not register in Visual Studio.You cannot view this attachment.
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

#5
That is so strange.
- I don't run in admin mode
 I have  Visual studio 22 on this Laptop with Windows 11
 I reference GXSurf28.dll and Imsigx28.dll

I recently shared a vbscript version for the macro recorder - does that work on your computer?
https://forums.turbocad.com/index.php?topic=30691.0
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

Trying to upload my visual studio project
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

TedTheCarpenter

Many thanks Nikki. I had to add Interop.GXSurfLib.dll as a reference to get your project to work. For some reason I cannot create the file by adding GXSurf30.dll (or GXSurf28.dll) as a reference. But now that I have Interop.GXSurfLib.dll from your project I can add it to my projects. I really appreciate the   time you put into solving this issue!
Ted D

2017 Pro, 2018>2023 Platinum
Windows 11 Pro 22H2  64GB
Ryzen 9 5900X 12 core
Radeon RX 6600 XT 8GB

nikkipollard

I am glad it worked. Visual studio automatically added the Interop to my reference - It obviously knows I am not clever enough to figure that out.
I had the same issue trying to work with another Cad applications API. I gave up.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h