Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert all the shapes in current support paths to drawing?

4 REPLIES 4
Reply
Message 1 of 5
Buzz0m
796 Views, 4 Replies

Insert all the shapes in current support paths to drawing?

My case is that I need to check the validity of shapes in .shx-files. My first thought was to insert them into a drawing with the "shape" -command but it might not be the best way.

 

What I'm asking is:

  1. Is there a way to get all the used (in the current dwg) shape names, and the reference .shx-file in a list (or two) via autolisp?
  2. Is there a way to check the geometry of ALL the shapes in ALL the shx listed in the support file paths?

Why I'm asking is because we use some special linetypes and there is a fear that some of the shx-files have faulty definitions. Atm I am not aware of a method of doing this efficiently.

 

I was thinking of doing this

  1.  Via script: load all .shx-files I am interested in into the current drawing
    https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/How-to...
  2. Use a lisp utilizing the "shape"-command to draw them in a grid with corresponding shx-sourcefile references as texts next to the shape
  3. Profit

I'm open to other suggestions and all help is appreciated 😃

 

- F

4 REPLIES 4
Message 2 of 5
Buzz0m
in reply to: Buzz0m

http://cadpanacea.com/_misc/downloads/fndshape.zip

 

This nice little lisp is probably half the answer.

 

;; ------------------------------------------------------------------
;; FNDSHAPE.LSP  Copyright 2006  R.K. McSwain  all rights reserved
;;
;;  Author: R.K. McSwain
;;
;;  Initial Release [27 FEB 2005]
;;
;;  Feel free to copy, and modify as desired, just
;;  retain this header and append as necessary.
;;
;;
;; ------------------------------------------------------------------
(defun c:fndshape
		  (/	  ENT
		   LT	  OUTPUT
		   SHPNST ST
		   FN	  FP
		   I	  INS
		   ITEM	  LTENT
		   LTNAME LTOBJ
		   OBJ	  OSTR
		   REF	  SHAPENM
		   SHAPENO
		   SHPN	  STENT
		   STNAME STOBJ
		   TMP
		  )
  (vl-load-com)
  (setq output '())

    ; Step 1 - Find complex linetypes that reference a SHAPE
  (while (setq lt (tblnext "ltype" (not lt)))
    (setq ltname (cdr (assoc 2 lt)))
    (setq ltObj (tblobjname "ltype" ltname))
    (setq ltEnt (entget ltObj))
    (setq i 0)
    (while (< i (length ltEnt))
      (setq item (nth i ltEnt))
      (if (and
	    (eq (car item) 74)
	    (eq (cdr item) 4)
	  )
	(progn
	  (setq shapeno (itoa (cdr (nth (1+ i) ltEnt))))
	  (setq
	    shapenm (cdr (assoc 3 (entget (cdr (nth (+ i 2) ltEnt)))))
	  )
	  (setq	ostr
		 (strcat "LINETYPE ["	  ltname
			 "] uses SHAPE # ["
			 shapeno	  "] in the file ["
			 shapenm	  "]"
			)
	  )
	  (setq	output (cons ostr output)
		i      10000
	  )
	)
      )
      (setq i (1+ i))
    )
  )

    ; Step 2 - Find loaded SHAPE FILES
  (while (setq st (tblnext "style" (not st)))
    (setq stname (cdr (assoc 2 st)))
    (setq stObj (tblobjname "style" stname))
    (setq stEnt (entget stObj))
    (if	(eq 1 (logand (cdr (assoc 70 stEnt)) 1))
      (setq ostr
		   (strcat "The following SHAPE FILE is loaded: ["
			   (vl-princ-to-string (cdr (assoc 3 st)))
			   "]"
		   )
	    output (cons ostr output)
      )
    )
    (setq i (1+ i))
  )

    ; Step 3 - Find inserted SHAPES
  (setq tmp (ssget "X" '((0 . "SHAPE"))))
  (if tmp
    (progn
      (setq i 0)
      (while (< i (sslength tmp))
	(setq obj (ssname tmp i))
	(setq ent (entget obj))
	(setq shpn (cdr (assoc 2 ent)))
	(if (not shpn)
	  (setq shpnST "An unknown shape ")
	  (setq shpnST (strcat "SHAPE named " shpn "] "))
	)
	(setq ins (cdr (assoc 10 ent)))
	(setq ref (cdr (assoc 2 (entget (cdr (assoc 330 ent))))))

	(setq ostr (strcat shpnST
			   "is INSERTED in "
			   ref
			   " at "
			   (vl-princ-to-string ins)
		   )
	)
	(setq output (cons ostr output))
	(setq i (1+ i))
      )
    )
  )
  (if output
    (progn
      (setq output (reverse output))
      (setq fn (strcat (getenv "temp") "\\fndshape.txt"))
      (setq fp (open fn "w"))
      (foreach item output
	(write-line item fp)
      )
      (close fp)
      (startapp "notepad" fn)
    )
    (alert "Nothing found")
  )
  (princ)
)
(princ "\n Type FNDSHAPE to run...")
(princ)
Message 3 of 5
Sea-Haven
in reply to: Buzz0m

Pretty sure have to find but there is a shx ->shp its old and not to be confused with Esri shp files. 

 

shp to shx is in Express.

 

Message 4 of 5
Buzz0m
in reply to: Sea-Haven

Good morning [at least where I am it's morning 😃 ]!

The tool @Sea-Haven is talking about is dumpshx.exe* and can be found in eg.  C:\Program Files\Autodesk\AutoCAD 2020\Express. It is run as an independent tool.

 

In my original post I was aware that I talked about "shapes" when I actually meant shapes compiled in autocad (.shx). If I would be able to get my .shx files to .shp how would I go on to inspect all the shapes in a neat and tidy way?

 

*Sidenote: Imho it is not clearly documented or then the information I need is really well hidden. I have tried to use it before but it has never succeeded and only crashed.

Message 5 of 5
Sea-Haven
in reply to: Buzz0m

You can run dumpshx from within autocad using "shell"

 

(command "shell" "c:\\program files\\........\\dumpshx c:\\myfiles\\Custom.shx >c:\\myfiles\\dumpshx.txt")

note the \\ needed for lisp.

 

You can open the text file created c:\myfiles\dumpshx.txt and read it line by line not sure if it helps.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report