Jump to content

Recommended Posts

Posted

Hi

 

I am trying to use this report:

 

http://blog.civil3dreminders.com/2012/03/alignment​-length-report.html

 

But these files seem to be for C3D 2011, and will not work with 2012. There is something at the end explaining what to do if you are using a diff version of C3D. I am just wondering if there is anyone that could adjust the files so it works in 2012? I am really not any good at VBA. Too confusing.

 

Cheers

Martin

Posted (edited)

Guys,

 

The author originally wrote the code in VBA.

 

The blog post linked above demonstrates how to accomplish a similar plug-in using VB.NET (hence the Visual Studio screenshots). The VBA module is not needed. :thumbsup:

 

But these files seem to be for C3D 2011, and will not work with 2012. There is something at the end explaining what to do if you are using a diff version of C3D. I am just wondering if there is anyone that could adjust the files so it works in 2012? I am really not any good at VBA. Too confusing.

 

Actually, the plug-in works exactly as advertised... Just tested using Civil 3D 2012... I personally think it's more work than is necessary (using the Microsoft.Office.Interop.Excel Library, when writing to a simple CSV would work), but still, it works.

Edited by BlackBox
Posted

... Also, FWIW - I *believe* that since this was done via ActiveX COM API originally, that there's still a means to do this with Visual LISP (which also uses ActiveX COM API).

 

Look into the AeccXUiLand.AeccApplication Object:

 

(vl-load-com)

(defun c:C3dComApi (/ file)
 (if
   (setq
       file (findfile
              (strcat
                (vl-registry-read
                  (strcat "HKEY_LOCAL_MACHINE\\"
                          (if vlax-user-product-key                    ; If 2013
                            (vlax-user-product-key)                    ; Use 2013 function
                            (vlax-product-key)                         ; Use legacy function
                          )
                  )
                  "ACADLOCATION"
                )
                "\\help\\civil_api_activex_reference.chm"
              )
            )
     )
   (startapp "explorer" file)
   (prompt "\n** File not found ** ")
 )
 (princ)
)

Posted

When I try and run the program, it gives me this error:

 

alignerror.PNG

Posted

ct_net.cannot.find.file.png

 

... That's because the plug-in has a reference to the Microsoft.Office.Interop.Excel Library, and it (the dependent reference) cannot be found on your system. I'll see what I can do to provide an adaptation that does not have this dependency, and instead uses basic .CSV instead.

Posted
[ATTACH=CONFIG]36852[/ATTACH]

 

... That's because the plug-in has a reference to the Microsoft.Office.Interop.Excel Library, and it (the dependent reference) cannot be found on your system. I'll see what I can do to provide an adaptation that does not have this dependency, and instead uses basic .CSV instead.

 

That would be fantastic, thank you very much for your help :)

Posted (edited)

I love it when something is simpler than I thought it would be... It seems that Autodesk was kind enough to expose the Alignment Object Properties to Visual LISP; no AeccXUiLand.AeccApplication Interface Object required for this task.

 

Enjoy! :beer:

 

(vl-load-com)

(defun c:ALR () (c:AlignmentsLengthReport))
(defun c:AlignmentsLengthReport (/ *error*)
 (princ "\rALIGNMENTSLENGTHREPORT ")

 (defun *error* (msg)
   (if file
     (close file)
   )
   (if oShell
     (vlax-release-object oShell)
   )
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** " msg " ** ")))                         ; Fatal error, display it
   )
   (princ)
 )

 ((lambda (acApp / ss oShell filePath file alignmentName alignmentLength)
    (if (and (setq ss (ssget "_x" '((0 . "AECC_ALIGNMENT"))))
             (setq oShell (vla-getinterfaceobject
                            acApp
                            "Shell.Application"
                          )
             )
             (setq filePath
                    (strcat
                      (vl-filename-directory
                        (vl-filename-mktemp)
                      )
                      "\\Alignments Length Report_"
                      (menucmd
                        "M=$(edtime,$(getvar,date),YYYY-MO-DD)"
                      )
                      ".csv"
                    )
             )
             (princ "\nWorking, please wait... ")
             (princ)
        )
      (progn
        (setq file (open filePath "w"))
        (write-line "Civil 3D Drawing:" file)
        (write-line
          (strcat (getvar 'dwgprefix) (getvar 'dwgname))
          file
        )
        (write-line "" file)
        (write-line "Alignment Name:,Length:" file)
        (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument acApp)))
          (if (and (setq alignmentName (vlax-get x 'name))
                   (setq alignmentLength (rtos (vlax-get x 'length)))
              )
            (write-line (strcat alignmentName "," alignmentLength) file)
          )
        )
        (vla-delete ss)
        (princ "Done.")
        (setq file (close file))
        (vlax-invoke oShell 'open filePath)
        (*error* nil)
      )
      (cond
        (ss
         (*error*
           "Error: Unable to create \"Shell.Application\" Object"
         )
        )
        ((*error* "No alignments found"))
      )

    )
  )
   (vlax-get-acad-object)
 )
)

Edited by BlackBox
Posted

I tried the lisp, but i get this error:

 

alignerror2.PNG

Posted

Must be something to do with my computer, maybe something not installed correctly?

Posted
I tried the lisp, but i get this error:

 

attachment.php?attachmentid=36854&d=1346337203

 

Must be something to do with my computer, maybe something not installed correctly?

 

My mistake :oops:... I accidentally left one of my global variables in the code, which has been corrected here.

Posted

Great, thanks a lot, it seems to work. Just a daft question though, where does the output file get saved? :P I have tried looking in the path where the drawing is, but not there.

Posted
Great, thanks a lot, it seems to work. Just a daft question though, where does the output file get saved? :P I have tried looking in the path where the drawing is, but not there.

 

The code I provided creates, then opens a temporary file, which you then have the option of saving or not. :thumbsup:

Posted

Oh man, I knew it would be a daft question, didnt realise it started a new excel sheet in the background :oops:

 

Thanks again mate, really kind of u to spend the time on this :)

Posted

Oh man, I knew it would be a daft question, didnt realise it started a new excel sheet in the background :oops:

 

The code actually does not start Excel, at least not exactly....

 

The code uses the Shell.Application Object to open the file with your computer's default application for .CSV files.

 

Basically, this means that someone with Excel installed (not version in particular) will have the file open in Excel, whereas someone without Excel may have the file open in Notepad.

 

... Just another great trick I learned from Lee (

 

Thanks again mate, really kind of u to spend the time on this :)

 

No worries; Happy to help. :beer:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...