AutoLISP

   
 

Free AutoLISP code snippets for AutoCAD

Please feel free to be inspired, cut&paste or if you have any feedback or questions go here. If you want some customization or anything else that you can come up with that we might help you with you're welcome to contact us.

Miscellaneous tips&trix for AutoCAD AutoLisp

Purge layer filters / delete layer filters in AutoCAD. You get it here at my blog or here.

; To set the a custom scale, first set the StandardScale property to acVpCustomScale,
; then use the property CustomScale to define the custom scale value.
; Code examples to play with follow


(setq al (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)))
(vla-get-CustomScale al)
(vla-put-StandardScale al acVpCustomScale)
(vla-put-StandardScale al acVpScaleToFit)
(vla-put-StandardScale al ac1_10)
(setq numerator 1)
(setq denominator 25)
(vla-setCustomScale al numerator denominator)
(vla-getCustomScale al 'numerator 'denominator)
(princ numerator)
(princ denominator)

; The is how you can do a PGP file reinitialization (reload)awing template file used by QNEW
;;; (ax:GetQnewPath)
(defun ax:GetQnewPath (/ prof key)
  (setq prof (vla-get-ActiveProfile (vla-get-profiles (vla-get-preferences (vlax-get-Acad-Object)))))
  (setq key (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" prof "\\General"))
  (vl-registry-read key "QnewTemplate")
)

;;; Set the drawing template file used by QNEW
;;; This writes it to the registry but is later dismissed and overwritten by AutoCAD
;;; (ax:SetQnewPath "M:\\CAD\\ACADISO.DWT")
(defun ax:SetQnewPath (QnewPath / prof key)
  (setq prof (vla-get-ActiveProfile (vla-get-profiles (vla-get-preferences (vlax-get-Acad-Object)))))
  (setq key (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" prof "\\General"))
  (vl-registry-write key "QnewTemplate" QnewPath)
)

;; Gets current template
(getenv "QnewTemplate")
"c:\\my files\\templates\\qnew.dwt"

and

;; Sets a different template
(setenv "QnewTemplate" "c:\\my files\\templates\\qnew.dwt")

or another approach because the above one is not working in newer versions of AutoCAD:

Using VBA where QnewPath is the Template File Name: ThisDrawing.Application.Preferences.Files.QNewTemplateFile = QnewPath

Using LISP: (vla-put-QNewTemplateFile (vla-Get-Files (vla-Get-Preferences (vlax-get-acad-object))) QnewPath)

This is how you can preset the Path type in the xref attach dialog box
;;; Sets the Xref Path type used in the xref attach dialog box
;;; Absolute Path: (SetPathType 0)
;;; Relative Path: (SetPathType 1)
;;; No Path: (SetPathType 2)

(defun SetPathType (v)
  (vl-load-com)
  (vl-registry-write
    (strcat
      "HKEY_CURRENT_USER\\"
      (vlax-product-key)
      "\\Profiles\\"
      (vla-get-activeprofile
	(vla-get-profiles
	  (vla-get-preferences (vlax-get-acad-object))
	)
      )
      "\\Dialogs\\XattachDialog"
    )
    "PathType"
    v
  )
)

;;; Gets the Xref Path type used in the xref attach dialog box
;;; 0 = Absolute Path
;;; 1 = Relative Path
;;; 2 = No Path

(defun GetPathType ()
  (vl-load-com)
  (vl-registry-read
    (strcat
      "HKEY_CURRENT_USER\\"
      (vlax-product-key)
      "\\Profiles\\"
      (vla-get-activeprofile
	(vla-get-profiles
	  (vla-get-preferences (vlax-get-acad-object))
	)
      )
      "\\Dialogs\\XattachDialog"
    )
    "PathType"
  )
)

 
© 2001-2008 JTB World. All rights reserved.