Results 1 to 6 of 6

Thread: Error VBA DimAligned

  1. #1
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Error VBA DimAligned

    I have problem with this VBA, anyone can Help???

    Code:
    Sub DimAlignd()
        
        Dim ws As Variant
        Dim ACAD As AcadApplication
        On Error Resume Next 
        Set ACAD = GetObject(, "AutoCAD.Application") 
        On Error GoTo 0 
        If ACAD Is Nothing Then
            Set ACAD = New AcadApplication 
            ACAD.Visible = True
        End If
        ACAD.ActiveDocument.Utility.Prompt "Bla Bla Bla...!"
        Dim Coords(0 To 2) As Double
        Dim Coords2(0 To 2) As Double
        
        Dim ObjEnt As AcadDimAligned
        Dim n As Integer 
        Dim LastRowXY As Integer
        Set ws = Worksheets("Coord_PENZ").Cells
        LastRowXY = ws(Rows.Count, 2).End(xlUp).Row
        Dim DimAligned As Variant
        For n = 2 To LastRowXY - 1
            Const Angl = 0.2
    
           Coords(0) = ws(n, 2) 
           Coords(1) = ws(n, 3) 
           Coords(2) = ws(n, 4)
          
           Coords2(0) = ws(n + 1, 2) 
           Coords2(1) = ws(n + 1, 3) 
           Coords2(2) = ws(n + 1, 4)
           
           Set ObjEnt = ACAD.ActiveDocument.ModelSpace
           .DimAligned Coords, Coords2, Angl
           ObjEnt.Update
         Next n
       
     End Sub
    Last edited by Ed Jobe; 2014-02-26 at 04:16 PM.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Error VBA DimAligned

    When asking for help with code please give more details. State what the problem is. What line of code is giving you a problem. What you expect to happen vs what actually is happening.
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Re: Error VBA DimAligned

    Thanks Ed Jobe,
    this my problem in ObjectEntity not work
    Set ObjEnt = ACAD.ActiveDocument.ModelSpace.DimAligned Coords, Coords2, Angl

  4. #4
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Re: Error VBA DimAligned

    this my file maybe anyone wanna try....
    Attached Files Attached Files

  5. #5
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

    Default Re: Error VBA DimAligned

    you must use AddDimAligned method wich has the sintax "RetVal = object.AddDimAligned(ExtLine1Point, ExtLine2Point, TextPosition)", where all parameters are three-element array of doubles.
    so try this

    Code:
    Option Explicit
    
    Sub DimAlignd()
        
    '    Dim ws As variant  '<---- I'd not use variant variable for what you already know it'll be a "Range" object
        Dim ws As range'<---- Use proper object type variable instead
        Dim ACAD As AcadApplication
    
        On Error Resume Next
        Set ACAD = GetObject(, "AutoCAD.Application")
        On Error GoTo 0
        If ACAD Is Nothing Then
            Set ACAD = New AcadApplication
            ACAD.Visible = True
        End If
    
        ACAD.ActiveDocument.Utility.Prompt "Bla Bla Bla...!"
        Dim Coords(0 To 2) As Double
        Dim Coords2(0 To 2) As Double
        Dim Coords3(0 To 2) As Double '<----------- add this
        
        Dim ObjEnt As AcadDimAligned
        Dim n As Integer
        Dim LastRowXY As Integer
        Set ws = Worksheets("Coord_PENZ").Cells ' <------- warning: you must be sure to executethis routine while "Coord_PENZ" is the active worksheet
        LastRowXY = ws(Rows.Count, 2).End(xlUp).Row
        Dim DimAligned As Variant
        For n = 2 To LastRowXY - 1
            Const Angl = 0.2
            
            Coords(0) = ws(n, 2)
            Coords(1) = ws(n, 3)
            Coords(2) = ws(n, 4)
            
            Coords2(0) = ws(n + 1, 2)
            Coords2(1) = ws(n + 1, 3)
            Coords2(2) = ws(n + 1, 4)
            
            Coords3(0) = (Coords2(0) + Coords(0)) / 2 '<----------- add this
            Coords3(1) = (Coords2(1) + Coords(1)) / 2 '<----------- add this
            Coords3(2) = (Coords2(2) + Coords(2)) / 2 '<----------- add this
            
            'Set ObjEnt = ACAD.ActiveDocument.ModelSpace '<----------- NO
            '.DimAligned Coords, Coords2, Angl           '<----------- NO this
            Set ObjEnt = ACAD.ActiveDocument.ModelSpace.AddDimAligned(Coords, Coords2, Coords3) '<----------- add this
            
            ObjEnt.TextRotation = Angl '<-----' I guess the Angl variable was to rotate dimension text
    
            ObjEnt.Update
                   
         Next n
       
     End Sub
    also note what I thought about the use of your "Angl" variable
    bye

  6. #6
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Re: Error VBA DimAligned

    Thankyou very much RicVBA, its work now
    thank alot to admin ...

Similar Threads

  1. Dimaligned LISP routine
    By CCarleton in forum AutoLISP
    Replies: 8
    Last Post: 2015-06-17, 05:45 PM
  2. Replies: 0
    Last Post: 2011-03-17, 06:54 PM
  3. Error closes Revit: An error has occurred while drawing the contents of this window.
    By chasen_forever in forum Revit Architecture - General
    Replies: 6
    Last Post: 2010-05-07, 03:38 PM
  4. Replies: 8
    Last Post: 2009-10-27, 12:03 PM
  5. Error when loading custom linetype - Error reading shape file
    By drafting.82475 in forum AutoCAD Customization
    Replies: 4
    Last Post: 2007-04-19, 07:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •