Offset Problem

Discussion in 'AutoCAD' started by gezjames, Feb 18, 2005.

  1. gezjames

    gezjames Guest

    I am trying to offset a 2D Polyline and I can get it to offset however if I try to asign the new line from the offset to an Object variable I get the the error message "Object variable or With block variable not set". I have declared my object variable as an AcadObject and also tried AcadPolyline and just Object but get the same error. My code is as follows:

    lLin = xln.Offset(-dist)

    Where -dist is taken from a text box on a form.

    Any suggestions.

    Thanks
    Gerry
     
    gezjames, Feb 18, 2005
    #1
  2. Your line is an object, so you have to use the "Set" syntax :

    Set lLin = xln.Offset(-dist)

    Arnaud
     
    Arnaud Lesauvage, Feb 18, 2005
    #2
  3. Ooops sorry that was totally wrong !!!

    The objects are returned in an array of objects, not in an object!

    Dim objArray as Variant
    Dim lLin as AcadLine

    objArray = xln.Offset(-dist)
    Set lLine = objArray(0)

    Arnaud
     
    Arnaud Lesauvage, Feb 18, 2005
    #3
  4. gezjames

    ClementZheng Guest

    Here is the example code for offset method from AutoCAD VBA Help.

    Sub Example_Offset()
    ' This example creates a light weight polyline
    ' and then offsets that polyline.

    ' Create the polyline
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
    points(10) = 4: points(11) = 1
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True
    ZoomAll

    MsgBox "Offset the polyline by 0.25.", , "Offset Example"

    ' Offset the polyline
    Dim offsetObj As Variant
    offsetObj = plineObj.offset(0.25)
    offsetObj(0).Color = acRed

    ZoomAll
    MsgBox "Offset completed.", , "Offset Example"

    End Sub
     
    ClementZheng, Feb 18, 2005
    #4
  5. Is this any help?

    Private Sub CommandButton1_Click()

    Dim plineObj As AcadLWPolyline
    Dim points(0 To 5) As Double
    Dim offsetObj As Variant
    Dim offsetsize As Double

    points(0) = 0: points(1) = 0 'points to create a triangle
    points(2) = 0: points(3) = 10
    points(4) = 10: points(5) = 5

    On Error GoTo 0

    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True
    ZoomExtents

    'need to add error checking to make sure textbox1 contains valid input
    here
    offsetsize = TextBox1.Value 'grab the offset size
    offsetObj = plineObj.offset(offsetsize) 'assign the object
    offsetObj(0).Color = acRed 'just because

    ZoomExtents
    End Sub

    James

    I try to asign the new line from the offset to an Object variable I get the
    the error message "Object variable or With block variable not set". I have
    declared my object variable as an AcadObject and also tried AcadPolyline and
    just Object but get the same error. My code is as follows:
     
    James McDonald, Feb 18, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.