Adding entities in VB

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
zebiya
Posts: 27
Joined: 14 Feb 2007, 22:45
Location: Spain

Adding entities in VB

Post by zebiya » 07 Jun 2007, 22:14

Hello, Im using CADImport.NET extended version and I need to do the following:
<ul>
<li> Open a DWG file </li>
<li> Select one or several polylines on screen </li>
<li> Retrieve all vertices in those polylines and store them in a collection</li>
<li> Create a new layer called "PROFILE", defining color and linetype <li> Paint al L-shaped polyline on top of each vertex (like an "L" letter) in new layer "PROFILE"</li>
<li> Save it all in DXF (or DWG, if possible) </li>
</li>
</ul>
Ñ—Could you please send me a piece of code in VB doing all those steps?

Thanks in advance

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 08 Jun 2007, 12:55

Hello!

We will prepare necessary code soon.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

zebiya
Posts: 27
Joined: 14 Feb 2007, 22:45
Location: Spain

Post by zebiya » 11 Jun 2007, 22:36

Thank you Sergey, please do not leave this in the "forgotten drawer" [;)]

I really need your help as soon as possible.

Thanks

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 14 Jun 2007, 13:49

Hello!

The following answers are based on Viewer demo from the extended version of <b>CAD Import .NET</b>.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><ul><li> Open a DWG file</li></ul><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Public Sub LoadFile(ByVal dlg As Boolean) contains the following lines:

Code: Select all

FCADImage = <font color="blue">New</font id="blue"> DWG.DWGImage
FCADImage.LoadFromFile(<font color="blue">Me</font id="blue">.openFileDlg.FileName)
which are responsible on opening DWG file.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><ul><li>
Select one or several polylines on screen</li>
<li>Retrieve all vertices in those polylines and store them in a collection</li>
<li>Create a new layer called "PROFILE", defining color and linetype</li>
<li>Paint al L-shaped polyline on top of each vertex (like an "L" letter) in new layer "PROFILE"</li>
<li>Save it all in DXF (or DWG, if possible) </li></ul><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Find in the <font color="blue">Public Sub</font id="blue"> LoadFile(<font color="blue">ByVal</font id="blue"> dlg <font color="blue">As Boolean</font id="blue">) and add <b>ChangeSelectionCond</b>(<font color="blue">False</font id="blue">) after <font color="blue">Me</font id="blue">.selEntityUse = <font color="blue">True</font id="blue">.

Find in the <font color="blue">Public Sub</font id="blue"> cadPictBox_MouseUp and add the following lines:

Code: Select all

<font color="blue">Dim</font id="blue"> Ent <font color="blue">As</font id="blue"> CADEntity
<font color="blue">Dim</font id="blue"> Poly <font color="blue">As</font id="blue"> CADPolyLine
<font color="blue">Dim</font id="blue"> Vert <font color="blue">As</font id="blue"> CADVertex
<font color="blue">Dim</font id="blue"> Layer <font color="blue">As</font id="blue"> CADLayer
<font color="blue">Dim</font id="blue"> LType <font color="blue">As</font id="blue"> CADLineType
<font color="blue">Dim</font id="blue"> LPoly <font color="blue">As</font id="blue"> CADPolyLine
<font color="blue">Dim</font id="blue"> LVert <font color="blue">As</font id="blue"> CADVertex
<font color="blue">Dim</font id="blue"> I <font color="blue">As Integer</font id="blue">
<font color="blue">Dim</font id="blue"> S <font color="blue">As String</font id="blue">

Ent = FCADImage.SelectExt(e.X, e.Y)

<font color="green">'add line type</font id="green">
LType = <font color="blue">Me</font id="blue">.FCADImage.Converter.LTypeByName("ISO dash")
<font color="blue">If</font id="blue"> LType <font color="blue">Is Nothing Then</font id="blue">
    LType = <font color="blue">New</font id="blue"> CADLineType
    LType.Name = "ISO dash"
    LType.Lines.Ticks.Add(1.2)
    LType.Lines.Ticks.Add(-0.3)
    <font color="blue">Me</font id="blue">.FCADImage.Converter.LinesByName("ISO dash")
    <font color="blue">Me</font id="blue">.FCADImage.Converter.GetSection(CADImport.ConvSection.LTypes).AddEntity(LType)
<font color="blue">End If</font id="blue">

<font color="green">'add layer</font id="green">
Layer = <font color="blue">Me</font id="blue">.FCADImage.Converter.LayerByName("PROFILE")
Layer.Color = Color.RoyalBlue
Layer.Visibility = <font color="blue">True</font id="blue">
Layer.SetLType(LType)
<font color="blue">Me</font id="blue">.FCADImage.Converter.Loads(Layer)

<font color="green">'Get vertexes from a polyline</font id="green">
<font color="blue">If TypeOf</font id="blue"> Ent <font color="blue">Is</font id="blue"> CADPolyLine <font color="blue">Then</font id="blue">
    Poly = <font color="blue">CType</font id="blue">(Ent, CADPolyLine)
    <font color="blue">For</font id="blue"> I = 0 <font color="blue">To</font id="blue"> Poly.Count - 1
        Vert = Poly.Vertexes(I)

        <font color="green">'add L-Shaped Polyline</font id="green">
        LPoly = <font color="blue">New</font id="blue"> CADPolyLine
        LPoly.Closed = False
        LPoly.Layer = Layer

        LVert = <font color="blue">New</font id="blue"> CADVertex
        LVert.Point = <font color="blue">New</font id="blue"> DPoint(0 + Vert.Point.X, 10 + Vert.Point.Y, 0 + Vert.Point.Z)
        LPoly.AddEntity(LVert)

        LVert = <font color="blue">New</font id="blue"> CADVertex
        LVert.Point = <font color="blue">New</font id="blue"> DPoint(0 + Vert.Point.X, 0 + Vert.Point.Y, 0 + Vert.Point.Z)
        LPoly.AddEntity(LVert)

        LVert = <font color="blue">New</font id="blue"> CADVertex
        LVert.Point = <font color="blue">New</font id="blue"> DPoint(5 + Vert.Point.X, 0 + Vert.Point.Y, 0 + Vert.Point.Z)
        LPoly.AddEntity(LVert)

        LPoly.Loaded(Me.FCADImage.Converter)
        <font color="blue">Me</font id="blue">.FCADImage.CurrentLayout.Entities.Add(LPoly)
        <font color="blue">Me</font id="blue">.FCADImage.Converter.OnCreate(LPoly)
    Next
    <font color="blue">Me</font id="blue">.cadPictBox.Invalidate()
    SaveAsDXF("c:\\LShapedPoly.dxf")
<font color="blue">End If</font id="blue">
Sergey.


Please post questions to the forum or write to support@cadsofttools.com

zebiya
Posts: 27
Joined: 14 Feb 2007, 22:45
Location: Spain

Post by zebiya » 02 Jul 2007, 20:16

Thanks a lot for your useful help. One last question Ñ—How can I implement a "ZoomAll" or "ZoomExtents" function?

Thanks in advance

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 04 Jul 2007, 14:20

Hello Zebiya,

Sorry for the delay.
Please find the following code in the <b>Viewer</b> demo.

Method <i>ResetScaling</i> is responsible on defining inner parameters for ZoomExtents functionality:

Code: Select all

<font color="blue">Public Sub</font id="blue"> ResetScaling()
    <font color="blue">Me</font id="blue">.scl = 1.0!
    <font color="blue">Me</font id="blue">.prev_scale = 1.0!
    <font color="blue">Me</font id="blue">.pos.X = ((<font color="blue">Me</font id="blue">.cadPictBox.ClientRectangle.Width - <font color="blue">Me</font id="blue">.curClRect.Width) / 2)
    <font color="blue">Me</font id="blue">.pos.Y = ((<font color="blue">Me</font id="blue">.cadPictBox.ClientRectangle.Height - <font color="blue">Me</font id="blue">.curClRect.Height) / 2)
    <font color="blue">Me</font id="blue">.cadPictBox.Invalidate()
<font color="blue">End Sub</font id="blue">
Method <i>DrawCADImage</i> draws image taking into account inner parameters specified by <i>ResetScaling</i>:

Code: Select all

<font color="blue">Public Sub</font id="blue"> DrawCADImage(<font color="blue">ByVal</font id="blue"> gr <font color="blue">As</font id="blue"> Graphics)
    <font color="blue">If</font id="blue"> (<font color="blue">Not Me</font id="blue">.FCADImage <font color="blue">Is Nothing</font id="blue">) <font color="blue">Then
        Try
            Me</font id="blue">.deactiv = <font color="blue">False
            Me</font id="blue">.Shift()
            <font color="blue">Dim</font id="blue"> ef1 <font color="blue">As New</font id="blue"> RectangleF(<font color="blue">Me</font id="blue">.pos.X, <font color="blue">Me</font id="blue">.pos.Y, (<font color="blue">Me</font id="blue">.curClRect.Width * <font color="blue">Me</font id="blue">.scl), (<font color="blue">Me</font id="blue">.curClRect.Height * <font color="blue">Me</font id="blue">.scl))
            <font color="blue">Me</font id="blue">.FCADImage.Draw(gr, ef1)
        <font color="blue">Catch</font id="blue"> obj1 <font color="blue">As</font id="blue"> Exception
        <font color="blue">End Try
    End If
End Sub</font id="blue">
Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Post Reply