Recent Posts

Pages: [1] 2 3 ... 10
1
AutoLISP (Vanilla / Visual) / Re: Apply Plot style table to all layout
« Last post by 3dwannab on Today at 02:56:38 PM »
Thanks @Lonnie for the correction.

Does anyone know why I get this message on ACAD 2023 and 2025?

This only happens on the first run.
2
AutoLISP (Vanilla / Visual) / Re: Lisp to e-mail content to helpdesk.
« Last post by Lonnie on Today at 12:36:38 PM »
I never did Publish the lisp.

Code: [Select]
;; Call IT Helpdesk Script

;; Using Outlook, this script will email selected objects in a temporary DWG file.
;; Credits to Ron Perez (ronjonp) for the Outlook example:
;; http://www.theswamp.org/index.php?topic=26953.msg324794#msg324794
;; http://www.theswamp.org/index.php?topic=55486.0
;; Lonnie Shaw 2020-01-06

;; Enter the Email Addresses Here as Strings
(setq *IT-Email* "lshaw@coname.net"
      *CC-Email* "bsmead@coname.net"
      *BCC-Email* "bseverson@coname.net; dsmith@coname.net; tmcauley@coname.net; jnewton@coname.net; pwyman@coname.net; rstock@coname.net; jarreola@coname.net"
      *Fileset1* (strcat "\nI need assistance from a CAD area Lead. Thank you!"
                         "\nExample file from"
                         "\n" (getvar "dwgprefix")
                         "\"" (getvar "dwgname") "\"")
)

(defun c:CRGhelp (/ _catch cc file outlook email sf si ni)

  ;; Load the Visual LISP extension
  (vl-load-com)

  ;; Define a helper function to catch errors
  (defun _catch (f a) (not (vl-catch-all-error-p (vl-catch-all-apply f a))))

  ;; Alert the user to select objects and send mail from Outlook
  (alert "Please create a scratch file by selecting the elements you are having problems with. \n\nAfter you select objects to mail, remember to send mail from Outlook.")

  (if
    (and
      ;; Get selected objects
      (or (ssget "_I") (prompt "\nSelect object(s) to eMail: ") (ssget))
      ;; Create a temporary DWG file
      (setq file (vl-filename-mktemp "" nil ".dwg"))
      (_catch 'vla-WBlock
              (list (cond (*AcadDoc*)
                          ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))))
                    file
                    (vla-get-activeselectionset *AcadDoc*)))
      ;; Create an Outlook application instance
      (setq outlook (vlax-get-or-create-object "Outlook.Application"))
      (setq sf (vl-catch-all-apply 'vlax-invoke (list (setq ns (vlax-invoke outlook 'GetNameSpace "MAPI")) 'GetDefaultFolder 5)))
      (setq si (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count)))
      ;; Create a new email item
      (setq email (vlax-invoke-method outlook 'CreateItem 0))
      ;; Set email subject
      (_catch 'vlax-put (list email 'Subject "Helpdesk Ticket: "))
      ;; Attach the temporary DWG file
      (_catch 'vlax-invoke (list (vlax-get email 'Attachments) 'Add file))
      ;; Add recipients
      (_catch 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *IT-Email*))
      (setq cc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *CC-Email*)))
      (setq bcc (vl-catch-all-apply 'vlax-invoke (list (vlax-get email 'Recipients) 'Add *BCC-Email*)))
      ;; Set recipient types
      (_catch 'vlax-put (list cc 'Type 2))  ;; CC
      (_catch 'vlax-put (list bcc 'Type 3)) ;; BCC
      ;; Set the email body
      (_catch 'vlax-put (list email 'Body *Fileset1*))
    )
    ;; Display the email in Outlook and handle file cleanup
    (progn
      (princ "\nOutlook active...")
      (vlax-invoke email 'Display :vlax-true)
      (if (= (vl-catch-all-apply 'vlax-get (list email 'Sent)) :vlax-true)
          (vl-file-delete file)
          (progn
            (if (= (setq ni (vl-catch-all-apply 'vlax-get (list (vlax-get sf 'items) 'count))) si)
                (vl-file-delete file) ;; No email was added to Sent Items - delete the file
            )
          )
      )
    )
  )
  ;; Release COM objects
  (foreach x (list sf ns email outlook) (and x (vlax-release-object x)))
  (princ)
)



3
AutoLISP (Vanilla / Visual) / Re: Lisp to e-mail content to helpdesk.
« Last post by Lonnie on Today at 12:35:44 PM »
Sorry I did not see this.

Here is what I got.

Command: (_GET-USERS-EMAIL-ADDY)
"lshaw@coname.net"

I ran this

Code: [Select]
(defun _get-users-email-addy (/ network user domain conn qry ldaprs fld result)
  (setq result nil) ; Initialize result to nil
  (vl-catch-all-apply
    '(lambda ()
       (setq
         network (vlax-create-object "Wscript.Network")
         user    (vlax-get network 'username)
         domain  (vlax-get network 'userdomain)
         conn    (vlax-create-object "ADODB.Connection")
       )
       (vlax-put conn 'provider "ADsDSOObject")
       (vlax-invoke conn 'open "ADSI")
       (setq
         qry    (strcat "select mail from 'LDAP://" domain "' ")
         qry    (strcat qry "WHERE objectClass = 'user' and ")
         qry    (strcat qry "samAccountName = '" user "'")
       )
       (princ (strcat "\nLDAP Query: " qry)) ; Print the LDAP query for debugging
       (setq ldaprs (vlax-invoke conn 'execute qry))
       (setq fld (vlax-invoke (vlax-get ldaprs 'fields) 'item "mail"))
       (setq result (vlax-get fld 'value))
    )
  )
  (if (eq 'str (type result))
    (progn
      (princ (strcat "\nEmail Address: " result)) ; Print the result for debugging
      result
    )
    (progn
      (princ "\nFailed to retrieve email address.")
      nil
    )
  )
)

and got

AP Query: select mail from 'LDAP://DCE' WHERE objectClass = 'user' and samAccountName = 'lshaw'
Email Address: lshaw@coname.net"lshaw@coname.net"

4
You may be able to do with VL lisp but like the .Net answer would create a cogo point with a description and put it in a CIV3D group say "TEXTS" then can use CIV3D label styles. May be faster to export all the text into a CSV file PXYZD then import file into a group.

If you look into the CIV3D samples there may be a VL example of import points. I know they exist, not on CIV3D at moment.
6
I am trying to think of a way to convert Dtext or Mtext to a Civil 3D label simply by selecting the text.  Some drawings come to me that have static text and I want to be able to convert these text objects to Civil 3D general Labels simply by clicking on them.  I understand I can use annotative text styles, but I would rather have them as general C3D labels.
7
Thank you Marko Ribar !
8
AutoLISP (Vanilla / Visual) / Re: Modify DWGUNITS
« Last post by JasonB on May 19, 2024, 01:54:55 AM »
The command is -DWGUNITS and not INSUNITS or LUNITS.

Please pay more attention before responding.

-DWGUNITS is a command.

INSUNITS and LUNITS are system variables

As others have pointed out, -DWGUNITS looks to be related to an AutoCAD Vertical. It's not documented anywhere that I could find in the HELP. Also, from other posts it seems geared more towards converting a drawing from one set of units to another. Further to this, the prompting of the command changes depending on whether you've run the command previously in a drawing. So simply calling
Code - Auto/Visual Lisp: [Select]
  1. (command "._-DWGUNITS" 6 2 3 "_N" "_Y")
may not work in all cases.

If you're simply trying to set the drawing units, then it would be better to explore the -UNITS command.

How to do it without COMMAND to look elegant within a program?

All the settings of the -UNITS command can be set via a system variable, which allows you to avoid making a command call from lisp. This is a more elegant approach. e.g
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'INSUNITS 6)
  2. (setvar 'LUNITS 2)
  3. (setvar 'LUPREC 4)
10
I mod. CAB's version in spare time...
I added GrSnap and few other options - calling OSNAP command during dragging...

Here is the link : https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/need-help-to-modify-code-quot-rotate-block-for-preview-prior/m-p/12782519/highlight/true#M466237
Pages: [1] 2 3 ... 10