Results 1 to 6 of 6

Thread: Problem in creating AcCmColor object

  1. #1
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Problem in creating AcCmColor object

    Hi all, I have a problem vhen trying to set a new layer color from VBA/Excel.
    If I use the following code:

    Code:
    Set acLayer = acadDoc.Layers.Add(sTag)
    Dim aCol As Object 'I have also tried with AcadAcCmColor
    Set aCol = acadApp.GetInterfaceObject("AutoCAD.AcCmColor") 'I have also tried with New AcadAcCmColor
    aCol.ColorMethod = acColorMethodByRGB
    aCol.ColorIndex = color
    acLayer.TrueColor = aCol
    I got a "Problem in loading Application" error when I try to create the aCol object.
    If I use Early Binding, the error is "Cannot find the specified module".

    Autocad (2016) loads fine and it's the only version installed.
    acadDoc is the AcadApplication object, sTag is the name of the new layer.

    How can i solve this?
    Thank you for the attention!

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Problem in creating AcCmColor object

    If memory serves, you need concatenate "AutoCAD.AcCmColor." and the first two characters of ACADVER sysvar.

    Now, I skipped VBA entirely, going from LISP --> .NET, so pseudo code might be something like:
    Code:
    Set acLayer = acadDoc.Layers.Add(sTag)
    Dim aCol As AcadAcCmColor
    Dim sVer As String = Left(acadDoc.GetVariable("ACADVER"), 2)
    Set aCol = acadApp.GetInterfaceObject("AutoCAD.AcCmColor." & sVer)
    aCol.ColorMethod = acColorMethodByRGB
    aCol.ColorIndex = color
    acLayer.TrueColor = aCol

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Re: Problem in creating AcCmColor object

    Thanks BlackBox,
    unfortunately this doesn't work, I got the same error.
    I previously tried by hardcoding the autacad version, same result.

    (BTW: VBA doesn't let you declare and initialize a variable in the same line... very annoying!)

    Maybe it's time to move the macro to a .NET plugin and using closedxml to read the excel file!

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Problem in creating AcCmColor object

    Quote Originally Posted by a.ghensi689507 View Post
    Thanks BlackBox,
    unfortunately this doesn't work, I got the same error.
    I previously tried by hardcoding the autacad version, same result.
    Well, shoot. *kicks dirt*

    I saw that you hard-coded, but wasn't sure if you used the correct version as that wasn't included in your OP. For that reason, I offered a VBA kludge that I hoped did what my 'blackout' LISP routine does (it changes any layer to black true color with 0.00 lineweight; I also have one for nested layers)... Curious to know if that LISP will work for you, as if not, perhaps there's a repair needed? *not sure*

    Code:
    (vl-load-com)
    
    (defun c:Blackout (/ *error* acDoc oLayers ss oLayer layers acColor)
      (princ "\rBLACKOUT ")
    
      (defun *error* (msg)
        (if ss
          (vla-delete ss)
        )
        (if acDoc
          (progn
            (vla-endundomark acDoc)
            (vla-regen acDoc acAllViewports)
          )
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat " ** Error: " msg " ** ")))
        )                                                                   ; Fatal error, display it
        (princ)
      )
    
      (if (ssget)
        (progn
          (vla-startundomark
            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (setq oLayers (vla-get-layers acDoc))
          (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
            (if
              (not
                (vl-position
                  (setq oLayer (vla-item oLayers (vla-get-layer x)))
                  layers
                )
              )
               (setq layers (cons oLayer layers))
            )
          )
    
          ;; blackout
          (setq acColor (vla-getinterfaceobject
                              (vlax-get-acad-object)
                              (strcat "AutoCAD.AcCmColor."
                                      (substr (getvar 'acadver) 1 2)
                              )
                            )
              )
          (vla-setrgb acColor 0 0 0)
          
          (foreach oLayer layers
            (vla-put-lineweight oLayer 0)
            (vla-put-truecolor oLayer acColor)
          )
        )
      )
      (*error* nil)
    )

    Quote Originally Posted by a.ghensi689507 View Post
    (BTW: VBA doesn't let you declare and initialize a variable in the same line... very annoying!)
    Thankfully, LISP doesn't require variable declaration... As for .NET, hooray C# (.NET generally), and Auto-Property Initializers! Haha


    Quote Originally Posted by a.ghensi689507 View Post
    Maybe it's time to move the macro to a .NET plugin and using closedxml to read the excel file!
    I know you're after VBA here, however, this old CSV->Layers LISP routine will get-or-create layers, and set their respective properties.

    If you need to quickly convert XLS/XLSx --> CSV, this Right Click Excel to CSV Windows Shell Context Menu might help.


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2015-01
    Posts
    27
    Login to Give a bone
    0

    Default Re: Problem in creating AcCmColor object

    Thanks BlackBox,
    I haven't tried the lisp you posted yet, but I found that the problem occurs only on my colleague's computer that has office 2016 installed. In my computer (Office 2013) everything runs fine using the GetInterfaceObject. Next week I'm going to investigate what is the real culprit an how to solve it!

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

    Default Re: Problem in creating AcCmColor object

    I've seen times where installing Office after Autocad messes up Autocad's vba. The solution was to reinstall autocad vba.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Creating a knot-like object
    By julian.perlstein368861 in forum AutoCAD 3D (2007 and above)
    Replies: 1
    Last Post: 2013-04-04, 01:08 PM
  2. Copy Object Properties Before Creating a Similar Object
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 8
    Last Post: 2012-07-01, 03:03 AM
  3. Creating orthographic projections from 3d object
    By herbertmunch in forum AutoCAD General
    Replies: 5
    Last Post: 2008-01-28, 09:31 PM
  4. CREATING TABLE FROM OBJECT DATA
    By VBOYAJI in forum AutoCAD Map 3D - General
    Replies: 6
    Last Post: 2006-02-27, 04:06 PM

Tags for this Thread

Posting Permissions

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