Print Page | Close Window

Add Region using .NET and late binding...

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=3408
Printed Date: 19.May.2026 at 10:51


Topic: Add Region using .NET and late binding...
Posted By: LittleOleMeDesi
Subject: Add Region using .NET and late binding...
Date Posted: 22.Mar.2010 at 15:02
I am trying to create a Region with .NET.  I am using late binding since I have to program to 3 different version of AutoCAD.

The following code works:

 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim V_Region As Object

        ' declare variables
        Const PI = 3.14159265358979
        Dim line1 As Object
        Dim line2 As Object
        Dim line3 As Object
        Dim arc1 As Object
        Dim center1(2) As Double
        Dim point1(0 To 2) As Double
        Dim point2(0 To 2) As Double
        Dim point3(0 To 2) As Double
        Dim point4(0 To 2) As Double

        point1(0) = 10 : point1(1) = 10 : point1(2) = 0
        point2(0) = 50 : point2(1) = 10 : point2(2) = 0
        point3(0) = 50 : point3(1) = 20 : point3(2) = 0
        point4(0) = 10 : point4(1) = 20 : point4(2) = 0

        line1 = V_AutoCad.ActiveDocument.ModelSpace.AddLine(point1, point2)
        line2 = V_AutoCad.ActiveDocument.ModelSpace.AddLine(point3, point4)
        line3 = V_AutoCad.ActiveDocument.ModelSpace.AddLine(point4, point1)
        center1(0) = line1.EndPoint(0) : center1(1) = line1.EndPoint(1) + 5
        center1(2) = 0
        arc1 = V_AutoCad.ActiveDocument.ModelSpace.AddArc(center1, 5, 3 / 2 * PI, 1 / 2 * PI)
        ' make array for region
        Dim arrayobj(3) As AcadEntity
        arrayobj(0) = line1
        arrayobj(1) = arc1
        arrayobj(2) = line2
        arrayobj(3) = line3
        ' make the region from the array

        V_Region = V_AutoCad.ActiveDocument.ModelSpace.AddRegion(arrayobj)
       

    End Sub


But when I change this line:
      Dim arrayobj(3) As AcadEntity
To:
      Dim arrayobj(3) As Object

I get "Invalid Object Array" on the AddRegion line.

Does anyone know how to fix this and stay as a late binding program???



Print Page | Close Window