Recent Posts

Pages: 1 2 3 [4] 5 6 ... 10
31
AutoLISP (Vanilla / Visual) / subentities of a block
« Last post by Jeremy2 on August 03, 2022, 03:37:13 PM »
I want to write a routine that takes the ename of a block and returns a list of all the subentities in that individual block. I want to process all the entities in the block and change their visibility state. I've tried this several times and the change takes effect on every block in the drawing. I don't want that, I want it to change on only the blocks I have picked. Any ideas how to stop this generic changing and focus on the individual block?
32
AutoLISP (Vanilla / Visual) / Re: Still learning, but now trying to make an "L" shape.
« Last post by GDF on August 03, 2022, 02:53:25 PM »
Look at AutoCAD’s dline.lsp that comes with AutoCAD.
33
AutoLISP (Vanilla / Visual) / Re: Need help to extract data from set of lines
« Last post by nekonihonjin on August 03, 2022, 11:04:49 AM »
Exactly what I needed Bigal, Thanks!

don't know what you mean with lines always 1- x

they were drawn in that order from 1 to 16, it's ok if I have to select lines one by one to make sure that the order matches the text number.



the little I know about it, I can change the lines that have the --- rtos (/lenght/)  2 X ---  to increase-decrease decimals, to be able to get one decimal in the total lenght.   And it needed the defun with a c: for it to wait until I call it. I was able to modify that.

but it returns a reverse order, the first line I pick is the last one in the table, I don't know what line needs to be modified for this to be first pick-first row of table.



Edit:
it was not the case of the example, so I didn't check right on, but if lines points to the left  (-x) it should also be only 0° to 90° range  and 0° to -90° if below horizontal,
gonna try to modify this on my own, but I donīt have to much expectations  :cry2:

Code: [Select]
  (if (> ang 180.0)
    (setq ang (rtos (- ang 360.0) 2 0))
    (setq ang (rtos ang 2 0))
  )


Edit2:

I did this for the angle thing,
Code: [Select]
    (if (> ang 270.0)
    (setq ang (rtos (+ -360 ang) 2 0))
    (  if (> ang 90.0)
    (setq ang (rtos (- 180 ang) 2 0))
    (setq ang (rtos ang 2 0))
  )

still no idea how to invert the order of the table items.
34
AutoLISP (Vanilla / Visual) / Re: Automatic layout LISP
« Last post by slj.engenharia@gmail.com on August 03, 2022, 10:04:23 AM »
hello renkor, i found your question and i have an answer after several years.
Of course you managed to solve it.
But I did it as a challenge.
(I'm sorry if I misspelled something, I used google translator)


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ a cnt en entg entg_pline lista n num_str p1 p2 pini pins pline pt
  2.              ss1 ss2)
  3.   (setvar "cmdecho" 0)
  4.   (command ".ucs" "world")
  5.   (if (null (tblsearch "layer" "defpoints"))
  6.     (command ".layer" "m" "defpoints" "c" "7" "" "")
  7.   )
  8.   (if (setq pline (entsel "\nSelect the road axis:"))
  9.     (progn
  10.       (redraw (car pline) 3) ;_highlight object
  11.       (if (setq pini (getpoint
  12.                        "\nSelect a point near the beginning of the road pline: "
  13.                      )
  14.           )
  15.         (progn
  16.           (setq entg_pline (entget (car pline)))
  17.           (setq lista nil)
  18.           (mapcar '(lambda (a)
  19.                      (if (= (car a) 10)
  20.                        (setq lista (cons (cdr a) lista))
  21.                      )
  22.                    )
  23.                   entg_pline
  24.           )
  25.           (if (< (distance pini (last lista)) (distance pini (car lista)))
  26.             (setq lista (reverse lista))
  27.           )
  28.           (setq ss1 (ssget "f" lista (list (cons '2 "viewport"))))
  29.           (setq cnt (sslength ss1))
  30.           (if (> cnt 0)
  31.             (progn
  32.               (setq n 0)
  33.               (repeat cnt
  34.                 (setq entg (entget (setq en (ssname ss1 n))))
  35.                 (setq n (1+ n))
  36.                 (setq pins (cdr (assoc 10 entg)))
  37.                 (setq pt (polar pins (cdr (assoc 50 entg)) 400))
  38.                 (setq p1
  39.                        (polar pins (+ (* pi 0.5) (cdr (assoc 50 entg))) 291.7293)
  40.                 )
  41.                 (setq p2
  42.                        (polar pins (+ (* pi 1.5) (cdr (assoc 50 entg))) 291.7293)
  43.                 )
  44.                 (setq p2 (polar p2 (cdr (assoc 50 entg)) 844.4204))
  45.                 (setq num_str (rtos n 2 0))
  46.                 (if (= (strlen num_str) 1)
  47.                   (setq num_str (strcat "0" num_str))
  48.                 )
  49.                 ;;;_the number is for verification
  50.                 ;;;_layer defpoints does not plot
  51.                 (entmakex (list (cons 0 "TEXT")
  52.                                 (cons 1 num_str)
  53.                                 (cons 10 pt)
  54.                                 (cons 11 pt)
  55.                                 (cons 8 "defpoints")
  56.                                 (cons 40 200)
  57.                                 (cons 50 (cdr (assoc 50 entg)))
  58.                                 (cons 72 1)
  59.                                 (cons 73 2)
  60.                           )
  61.                 )
  62.                 (command ".-layout" "copy" "template" num_str)
  63.                 (command ".-layout" "set" num_str)
  64.                 (setq
  65.                   ss2 (ssget
  66.                         "x"
  67.                         (list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab")))
  68.                       )
  69.                 )
  70.                 (vla-put-displaylocked (vlax-ename->vla-object (ssname ss2 0))
  71.                                        :vlax-false
  72.                 )
  73.                 (command ".mspace")
  74.                 (command ".ucs" "ob" en)
  75.                 (command ".plan" "")
  76.                 (command ".zoom" "w" (trans p1 0 1) (trans p2 0 1))
  77.                 (command ".pspace")
  78.                 (setvar "tilemode" 1)
  79.               )
  80.               (command ".-layout" "delet" "template")
  81.             )
  82.           )
  83.         )
  84.       )
  85.     )
  86.   )
  87.   (if pline
  88.     (redraw (car pline) 4) ;_unhighlight object
  89.   )
  90.   (princ)
  91. )


EDIT (John): Added code tags.
35
BricsCAD Users / Findfile + LEGACYCODESEARCH in BricsCAD
« Last post by BricscadBoy on August 03, 2022, 05:19:47 AM »
Has anyone else noticed the change in LISP findfile behaviour in recent BricsCAD releases?

With V19 they added LEGACYCODESEARCH system variable, but it had no effect.
With V20 on, BricsCAD has LEGACYCODESEARCH, SECURELOAD, and TRUSTEDPATHS. All of which are now enabled.
It's not that well documented. Mainly discussed here
https://developer.bricsys.com/bricscad/help/en_US/V22/DevRef/index.html?page=source%2FApplicationSecurity.htm

The Lisp Developer Support Package (LDSP) includes some registry snipits in the security folder to change the behaviour back to legacy. This requires Admin access, as these are under the HKEY_LOCAL_MACHINE
https://boa.bricsys.com/applications/a/?lisp-developer-support-package-(ldsp)-a720-al1176

If you're a CAD admin and you want to set TRUSTEDPATHS, then you would need to edit the registry key. As far as I'm aware there is no interface provided to set.

I find the LISP findfile behaviour annoying as it now fails to find files in the current drawing folder. I know they have simply implemented the same functionality as AutoCAD, but I don't get the logic of having a function to find files that doesn't always find files!

I commonly store files in the same folder as the current drawing. These aren't LISP, often just simple text files.

LEGACYCODESEARCH is not offering any protection, as it you can simply build a new search function to get around the limitation. here are a couple of examples that follow legacy behaviour to findfiles.

Code - Auto/Visual Lisp: [Select]
  1. ;LEGACYFINDFILE
  2.  
  3. ; Provides legacy findfile behaviour without the need of setting LEGACYCODESEARCH = 1
  4. ; Searches in the following order:
  5. ; - If a folder path is included with the filename, searches just there.
  6. ; - Current drawing folder.
  7. ; - Start-In folder. This is the folder that the progam has been launched from
  8. ; - Installation folder. Folder that application has been installed in.
  9. ; - Folders listed on search path, normal findfile behaviour
  10.  
  11.  
  12. (defun legacyfindfile (fn / startin dwgfolder installkey installfolder return)
  13.         (setq startin (strcat (vl-string-right-trim "\\." (findfile ".")) "\\")) ; Finds the Start-In folder. BricsCAD returns the "\\." AutoCAD doesn't
  14.         (setq dwgfolder (getvar 'DWGPREFIX)) ; current drawing folder
  15.         ; Retrieve the Installation folder from registry. BricsCAD returns the "\\" AutoCAD doesn't
  16.         (setq installkey (if (= (getvar 'PROGRAM) "BRICSCAD") "InstallDir" "acadlocation")) ; reg key is application specific
  17.         (setq installfolder (strcat (vl-string-right-trim "\\" (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key)) installkey)) "\\"))
  18.         (cond
  19.       ; GIVEN FOLDER
  20.       ; If the filename includes the path or starts with "."
  21.       ((or (/= (vl-filename-directory fn) "") (= (substr fn 1 1) "."))
  22.                                 (setq return (findfile fn))
  23.                         )
  24.                         ; CURRENT DRAWING FOLDER
  25.                         ; If the drawing has been saved, then search the current dwgfolder for the file
  26.                         ((and (= (getvar 'dwgtitled) 1) (setq return (findfile (strcat dwgfolder fn))))
  27.                          return
  28.                         )
  29.                         ; START-IN FOLDER
  30.                         ; Search the start-in folder for the file.
  31.                         ; This step may not be necessary as normal findfile searches here in anycase.
  32.                         ; However, this does insure that it follows legacy search order
  33.                         ((setq return (findfile (strcat startin fn)))
  34.                          return
  35.                         )
  36.                         ; INSTALL FOLDER
  37.                         ; Search the installation folder for the cad application
  38.                         ; again not necessary as normal findile searches here too
  39.                         ((setq return (findfile (strcat installfolder fn)))
  40.                          return
  41.                         )
  42.       ; SEARCH PATH
  43.       ; Use standard findfile behavior to search the support file search path
  44.                         (T (setq return (findfile fn)))
  45.         )
  46. return
  47. )


Code - Auto/Visual Lisp: [Select]
  1. ; BCADLEGACYFINDFILE
  2. ; Does the same based on a specific list of folders.
  3. ; Requires BricsCAD VLE Extension for it to work in AutoCAD
  4.  
  5. (defun bcadlegacyfindfile (fn / searchfolders installkey flag return)
  6.   (cond
  7.     ; GIVEN FOLDER
  8.     ; If the filename includes the path, or starts with "."
  9.      ((or (/= (vl-filename-directory fn) "") (= (substr fn 1 1) "."))
  10.           (setq return (findfile fn))
  11.      )
  12.      ; SEARCH FOLDERS
  13.      ; Search for the file across our list of searchfolders
  14.     (T
  15.       ; Build search folder list
  16.       ; Current drawing
  17.        (if (= (getvar 'dwgtitled) 1) (setq searchfolders (getvar 'DWGPREFIX)))
  18.        ; Start-in
  19.        (setq searchfolders (strcat searchfolders ";" (findfile ".")))  ; Finds the Start-In folder.
  20.        ; Installation folder.
  21.        (setq installkey (if (= (getvar 'PROGRAM) "BRICSCAD") "InstallDir" "acadlocation"))  ; reg key is application specific
  22.        (setq searchfolders (strcat searchfolders ";" (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key)) installkey)))
  23.        ;Support file search path
  24.        (setq searchfolders (strcat searchfolders ";" (getenv "ACAD")))
  25.        ;convert to list and clean up path end
  26.        (setq searchfolders (mapcar '(lambda (fol) (strcat (vl-string-right-trim "\\." fol) "\\")) (vle-string-split ";" searchfolders)))
  27.        (setq flag T)
  28.         (while (and flag searchfolders)
  29.           (cond
  30.             ((setq return (findfile (strcat (car searchfolders) fn)))
  31.                    (setq flag nil)
  32.             )
  33.             (T (setq searchfolders (cdr searchfolders) flag T))
  34.           )
  35.         )
  36.     )
  37.   )
  38.   return
  39. )
36
.NET / Re: C#10 not all code working fine
« Last post by kdub on August 03, 2022, 03:37:55 AM »
@gile thanks for information
@kdub your visual studio  2022 and for
Autocad 2023 whats is latest languange version ?

@daboho

.NET Framework 4.8 uses C# 7.3, so your code will be restricted to it's features.
As previously mentioned, AutoCAD requires the .NET Framework, not .Net Core and not .Net 5.0

<< ... >>

added:
This
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-450FD531-B6F6-4BAE-9A8C-8230AAC48CB4
documents the expectations,
though a later version of VS can be used ; ie I'm using VS2022 with AutoCAD 2023 (.net Framework 4.8 )

Regards,
37
.NET / Re: C#10 not all code working fine
« Last post by daboho on August 03, 2022, 03:33:03 AM »
@gile thanks for information
@kdub your visual studio  2022 and for
Autocad 2023 whats is latest languange version ?
38
.NET / Re: C#10 not all code working fine
« Last post by gile on August 03, 2022, 02:39:03 AM »
Records
and static local functions
and recursive patterns
and relational patterns
and coalescing assignment
and index operator
and range operator
and the other good stuff after C# 7.3 aren't available, which is a pain in the butt.

All these features were available in F# since .NET Framework 2.0.
39
AutoLISP (Vanilla / Visual) / Re: Need help to extract data from set of lines
« Last post by BIGAL on August 03, 2022, 01:07:38 AM »
A couple of questions are the lines always 1- x etc, where they drawn in that order 1 -> 16, just means just pick lines and start at a number eg 1.

Code: [Select]
; http://www.theswamp.org/index.php?topic=57753.0
; simple table example lines to table
l By AlanH Aug 2022

(defun rtd (a)
(/ (* a 180.0) pi)
)

(defun pl-table ( / ss sp curspace tableobj k totlen x len ang rownum)
(setq ss (ssget (list (cons 0 "LWPOLYLINE"))))

(setq sp (vlax-3d-point (getpoint "\nPick point for top left of table ")))

(Setq curspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq tableobj (vla-addtable curspace sp 2 3 1 25))
(vla-settext tableobj 0 0 "Heading")
(vla-settext tableobj 1 0 "No.")
(vla-settext tableobj 1 1 "Length")
(vla-settext tableobj 1 2 "Angle")

(setq k 0 totlen 0.0)
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
  (setq totlen (+ totlen (vlax-get obj 'Length)))
  (setq len (strcat (rtos (vlax-get obj 'Length) 2 2) " m"))
  (setq ang (rtd (angle (vlax-curve-getstartPoint obj)(vlax-curve-getEndPoint obj))))
  (if (> ang 180.0)
    (setq ang (rtos (- ang 360.0) 2 0))
    (setq ang (rtos ang 2 0))
  )
  (setq tableobj (vlax-ename->vla-object (entlast)))
  (setq rownum (vla-get-rows tableobj))
  (vla-InsertRows tableobj  rownum  (vla-GetRowHeight tableobj (- rownum 1)) 1)
  (vla-settext tableobj rownum 0 (rtos (setq K (1+ k)) 2 0))
  (vla-settext tableobj rownum 1 len)
  (vla-settext tableobj rownum 2 ang)
)

(setq tableobj (vlax-ename->vla-object (entlast)))
(setq rownum (vla-get-rows tableobj))
(vla-InsertRows tableobj  rownum  (vla-GetRowHeight tableobj (- rownum 1)) 1)
(vla-settext tableobj rownum 0  "Total")
(vla-settext tableobj rownum 1 (strcat (rtos totlen 2 0) " m"))

(princ)
)
(pl-table)

When it asks to select object type F and can drag lines over your red lines, press enter twice to end selection, then pick a point.
40
AutoLISP (Vanilla / Visual) / Re: Still learning, but now trying to make an "L" shape.
« Last post by BIGAL on August 02, 2022, 11:26:25 PM »
As you say use the getreal etc multiple times then when ready add the multi getvals.

Have a look at this re dims.

Code: [Select]
; simple draw a box and dimension it
; By Alan H March 2019


(defun ah:box ( / pt1 pt2 pt3 ahl ahh ahoff )
(setq oldsnap (getvar 'osmode))
(setq oldang (getvar 'angdir))
(setq pt1 (getpoint "\nPick lower left"))
(setvar 'osmode 0)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Simple rectang" "Enter length" 8 7 "1" "Enter height " 8 7 "2")))
(setq ahL (atof (nth 0 ans)))
(setq ahH (atof (nth 1 ans)))
(setq pt2 (polar pt1 0.0 ahl))
(setq pt3 (polar pt2 (/ pi 2.0) ahH))
(command "rectang" pt1 pt3)
(setq ahoff (* 2.0 (* (getvar 'dimasz)(getvar 'dimscale)))) ; change offset as required
(setq pt4 (polar pt2  (* pi 1.5) ahoff))
(command "dim" "hor" pt1 pt2 pt4 "" "exit")
(setq pt4 (polar pt3 0.0 ahoff))
(command "dim" "Ver" pt2 pt3 pt4 "" "exit")
(setvar 'osmode oldsnap)
)
(ah:box)

Pages: 1 2 3 [4] 5 6 ... 10