<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11264153#M3224</link>
    <description>&lt;P&gt;I think you should have started your own thread on this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried setting a breakpoint and stepping through the code to find the line at which you get an error?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 15:07:06 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2022-06-28T15:07:06Z</dc:date>
    <item>
      <title>AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10486734#M3220</link>
      <description>&lt;P&gt;pi = 3.xxx-xxxxxxxx&lt;BR /&gt;Dim StartPoint(0 To 2) As Double&lt;BR /&gt;Dim EndPoint(0 To 2) As Double&lt;BR /&gt;Dim Line(0 To 3) As Object&lt;BR /&gt;&lt;BR /&gt;StartPoint(0) = 0: StartPoint(1) = 0: StartPoint(2) = 0&lt;BR /&gt;EndPoint(0) = 1: EndPoint(1) = 0: EndPoint(2) = 0&lt;BR /&gt;Set Line(0) = ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint)&lt;BR /&gt;StartPoint(0) = 1: StartPoint(1) = 0: StartPoint(2) = 0&lt;BR /&gt;EndPoint(0) = 1: EndPoint(1) = 1: EndPoint(2) = 0&lt;BR /&gt;Set Line(1) = ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint)&lt;BR /&gt;StartPoint(0) = 1: StartPoint(1) = 1: StartPoint(2) = 0&lt;BR /&gt;EndPoint(0) = 0: EndPoint(1) = 1: EndPoint(2) = 0&lt;BR /&gt;Set Line(2) = ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint)&lt;BR /&gt;&lt;BR /&gt;StartPoint(0) = 0: StartPoint(1) = 0.5: StartPoint(2) = 0&lt;BR /&gt;&lt;BR /&gt;Set Line(3) = ThisDrawing.ModelSpace.AddArc(StartPoint, 0.5, pi / 2, 3 * pi / 2)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Dim Region1 As AcadRegion&lt;BR /&gt;Region1 = ThisDrawing.ModelSpace.AddRegion(Line)&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 02:44:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10486734#M3220</guid>
      <dc:creator>xxaaron</dc:creator>
      <dc:date>2021-07-22T02:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10486802#M3221</link>
      <description>&lt;P&gt;In the following 2 lines of your code, there are 2 errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Dim Region1 As AcadRegion&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Region1 = ThisDrawing.ModelSpace.AddRegion(Line)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. since Region1 is declared as AcadRegion object, when assigning an object value to it, you must use "Set" keyword, like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Set Region1 = ....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is why the error message saying "... object variable...no set..."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. However, the real error of your code is that your code treats the return value of AddRegion() method wrong: the returned value is AN ARRAY of AcadRegion object (i.e. one or more region objects), not a single AcadRegion object.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That is, the code should be&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Dim regions As Variant&lt;BR /&gt;regions = ThisDrawing.ModelSpace.AddRegion(Line)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then, you can look up the returned array for all possible regions. If you are sure the lines would only form one region, you can&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Dim region As AcadRegion&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Set region = regions(0)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'' Then do somethoing with the region&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;... ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 03:54:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10486802#M3221</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-07-22T03:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10488566#M3222</link>
      <description>Hi Norman,&lt;BR /&gt;&lt;BR /&gt;Thank you very much, it worked perfectly.&lt;BR /&gt;&lt;BR /&gt;Aaron Cowen, PE&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jul 2021 17:10:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/10488566#M3222</guid>
      <dc:creator>xxaaron</dc:creator>
      <dc:date>2021-07-22T17:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11263701#M3223</link>
      <description>&lt;P&gt;Actually I have created a shape using polyline and trying to make region out of it so that using massprop i can get area, inertia, centroid. But i am getting runtime error 424. Please help me resolve this issue for following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Private Sub CommandButton1_Click()&lt;/P&gt;&lt;P&gt;Dim acadapp As AcadApplication 'creating autocad application&lt;BR /&gt;Dim dwg As AcadDocument&lt;BR /&gt;Dim polyL As AcadLWPolyline&lt;BR /&gt;Dim copoly() As Double&lt;BR /&gt;Dim i As Integer&lt;BR /&gt;Dim j As Integer&lt;BR /&gt;Dim k As Integer&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Dim lastrow As Integer&lt;BR /&gt;''''''''''''''''''''''''''''''''&lt;BR /&gt;'check if autocad is open&lt;BR /&gt;On Error Resume Next&lt;BR /&gt;Set acadapp = GetObject(, "AutoCAD.Application")&lt;BR /&gt;On Error GoTo 0&lt;/P&gt;&lt;P&gt;'IF autocad app is not opened create a new instance and make it visible.&lt;BR /&gt;If acadapp Is Nothing Then&lt;BR /&gt;Set acadapp = New AcadApplication&lt;BR /&gt;acadapp.Visible = True&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;'Check if there is an active drawing running&lt;BR /&gt;On Error Resume Next&lt;BR /&gt;Set dwg = acadapp.ActiveDocument&lt;BR /&gt;On Error GoTo 0&lt;/P&gt;&lt;P&gt;'No active drawing found. Create a new one.&lt;BR /&gt;If dwg Is Nothing Then&lt;BR /&gt;Set dwg = acadapp.Documents.Add&lt;BR /&gt;acadapp.Visible = True&lt;BR /&gt;End If&lt;BR /&gt;'''''''''''''''''''''''''&lt;BR /&gt;Sheet1.Activate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lastrow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row&lt;BR /&gt;ReDim copoly((2 * lastrow) - 1)&lt;/P&gt;&lt;P&gt;k = 0&lt;BR /&gt;For i = 1 To lastrow&lt;BR /&gt;For j = 1 To 2&lt;BR /&gt;copoly(k) = Sheet1.Cells(i, j)&lt;BR /&gt;k = k + 1&lt;BR /&gt;Next j&lt;BR /&gt;Next i&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Set polyL = dwg.ModelSpace.AddLightWeightPolyline(copoly)&lt;BR /&gt;polyL.Closed = True&lt;/P&gt;&lt;P&gt;Dim region As Variant&lt;BR /&gt;region = thisdrawing.ModelSpace.AddRegion(polyL)&lt;/P&gt;&lt;P&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 12:36:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11263701#M3223</guid>
      <dc:creator>abhi.rathod</dc:creator>
      <dc:date>2022-06-28T12:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11264153#M3224</link>
      <description>&lt;P&gt;I think you should have started your own thread on this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried setting a breakpoint and stepping through the code to find the line at which you get an error?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 15:07:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11264153#M3224</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2022-06-28T15:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: AddRegion Fails - Run-Time error 91 - Object variable or with block variable not set SEE CODE BELOW</title>
      <link>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11265626#M3225</link>
      <description>&lt;P&gt;yes&amp;nbsp; definitely.&amp;nbsp; Code is running perfectly and creating a random shape using coordinates through polyline but in last line it is not able form a region and showing runtime error.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 05:10:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/addregion-fails-run-time-error-91-object-variable-or-with-block/m-p/11265626#M3225</guid>
      <dc:creator>abhi.rathod</dc:creator>
      <dc:date>2022-06-29T05:10:25Z</dc:date>
    </item>
  </channel>
</rss>

