Jump to content

List image names for renaming


gschmidt

Recommended Posts

Hi,

 

I have to rename ridiculous Image reference names in multiple drawings. e.g.:

"GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors"

(the drawings are generated in other software then AutoCAD)

 

In some cases there are 2 or more reference images in the drawing.

However, when I "SSGET" them, the order of the images in the selection set is random.

I want to sort (ascending) the existing names in a list based on a part (TVW0101) of the image reference name.

Only the first 2 digits after TVW are unique; In the example 01. the other Image in my example drawing is TVW0301-->03.

 

When I try to put the names in a list I get an stringp error.

Can somebody figure out what is wrong with the code?

 

(defun c:IMREN ( / img_len img_nr dwg_len nm vl sset)
(vl-load-com)
(if (setq ss (ssget "x" '((0 . "IMAGE"))))
	(progn
		(setq cnt 0)
		(repeat (sslength ss)
			(setq sset (ssname ss cnt))
			(setq vl (vlax-ename->vla-object sset))
			(setq nm
				(append nm (list (vla-get-name vl)))
			)				
			(setq cnt (1+ cnt))
		)
	)
)
(princ)
)

Link to comment
Share on other sites

Hi,

 

I have to rename ridiculous Image reference names in multiple drawings. e.g.:

"GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors"

(the drawings are generated in other software then AutoCAD)

 

In some cases there are 2 or more reference images in the drawing.

However, when I "SSGET" them, the order of the images in the selection set is random.

I want to sort (ascending) the existing names in a list based on a part (TVW0101) of the image reference name.

Only the first 2 digits after TVW are unique; In the example 01. the other Image in my example drawing is TVW0301-->03.

 

eg.

 

(setq l
      '("GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0801_Depth Colors"
        "GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0701_Depth Colors"
        "GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0501_Depth Colors"
       )
)
(vl-sort l '(lambda (j k) (< (atoi (substr j 121 2)) (atoi (substr k 121 2)))))

Returns.

 

("GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0501_Depth Colors" 
"GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0701_Depth Colors" 
"GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0801_Depth Colors") 

Link to comment
Share on other sites

Thanx for quick reply, however part of the problem is that when i try to put all images in a list I get a stringp error

 

(setq nm
(append nm (list (vla-get-name vl)))
)

 

(set nm (vla-get-name vl)) returns no error but doesn't append the value in a list

Link to comment
Share on other sites

No need to convert to Vla-object IMO , so try the following .

 

(defun c:IMREN ( / ss cnt sset names)
   (if (setq ss (ssget "_X" '((0 . "IMAGE"))))
     (repeat (setq cnt (sslength ss))
           (setq sset (ssname ss (setq cnt (1- cnt))))
           (setq names (append names (list (cdr (assoc 1 (entget (cdr (assoc 340 (entget sset)))))))))
           ))
(if names names (princ))
)

Link to comment
Share on other sites

Yes I do need to use the VLA-Object, because the Saved Path (file) name is different than the Image Reference name!!! I know it is strange, but this drawing is prepared in a different software than AutoCAD....

 

Saved Path:

"Gamba Post Mattress Installation Survey with cross profiles - 10.4923-DRA.DOC-4-3-0705 - Out Survey - Version Z01_TVW0101_Depth Colors.png"

(even no path is mentioned just the filename!)

 

Image Reference Name:

"GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors"

Link to comment
Share on other sites

GTRGES-VOO-TER-LA-4024-00069-02_Z01.jpg

 

For a project we have to rename 100 drawings to a client drawing number.

However when we rename the images the image path needs to be updated.

So I try to make a lisp/script to automize this action.

The files (DWG and PNG) you see are already the new client names, I only need to update the image link

 

DWG was too large I have deleted some objects, but I kept the images

this is a DWG file with 2 PNG Images, but the amount of images can differ from 1 to max. 5

 

Thanx for looking too it

GTRGES-VOO-TER-LA-4024-00069_Z01.dwg

GTRGES-VOO-TER-LA-4024-00069-01_Z01.jpg

Link to comment
Share on other sites

My full code is this, because I also have drawings with only 1 image.

Drawings with only one image: DWG and PNG get exactly the same (client) name

Drawings with >1 image: DWG and PNG get the same (client) name, but the PNG have extra "-01","-02" in the name.

 

The condition with only 1 picture is working!

 

(defun c:IMREN ( / img_len img_nr dwg_len nm vl sset)
(vl-load-com)
(if (setq ss (ssget "x" '((0 . "IMAGE"))))
	(cond
		((= (sslength ss) 1)
			(progn
				(setq sset (ssname ss 0))
				(setq vl (vlax-ename->vla-object sset))
				(setq nm (vla-get-name vl))
				(setq dwgpath (getvar "DWGPREFIX"))
				(setq dwgname (strcat (vl-filename-base (getvar "DWGNAME"))))
				(setq path (strcat dwgpath dwgname ".png"))
				(command "-image" "p" nm path)
				(vlax-put-property vl 'Name dwgname)
			)
		)
		((> (sslength ss) 1)
			(progn
				(setq cnt 0)
				(setq str "Z01")
				(repeat (sslength ss)
					(setq sset (ssname ss cnt))
					(setq vl (vlax-ename->vla-object sset))
					;(setq nm (vla-get-name vl))
					(setq nm
						(append nm (list (vla-get-name vl)))
					)				
					(princ nm)
					(setq dwgpath (getvar "DWGPREFIX"))
					(setq dwgname (strcat (vl-filename-base (getvar "DWGNAME"))))
					(setq dwg_len (- (strlen dwgname) (+ (strlen str) 1)))
					(setq revnr (substr dwgname (+ dwg_len 1))) 
					(setq imgname (substr dwgname 1 dwg_len))
					
					;(if 
						(setq path (strcat dwgpath imgname "-" (strcat "0" (itoa cnt)) revnr ".png"))
						(command "-image" "p" (nth cnt nm) path)
						(vlax-put-property vl 'Name dwgname)
					
					
					(setq cnt (1+ cnt))
				)
			)
		)
	)
	(princ "Error - No images in drawing!.")
)
(princ)
)

Link to comment
Share on other sites

Try this routine to see the image names in order .

 

(defun c:Test (/ ss cnt sset names)
 (if (setq ss (ssget "_X" '((0 . "IMAGE"))))
   (repeat (setq cnt (sslength ss))
     (setq sset (ssname ss (setq cnt (1- cnt))))
     (setq names
            (append
              names
              (list
                (vl-filename-base
                  (cdr (assoc 1 (entget (cdr (assoc 340 (entget sset))))))
                )
              )
            )
     )
   )
 )
 (if names
   (vl-sort names
            '(lambda (j k)
               (< (atoi (substr j 121 2)) (atoi (substr k 121 2)))
             )
   )
   (princ)
 )
)

Link to comment
Share on other sites

Yes they are in order, but this is the Saved Path name and not the Reference Name?

The command (command "-image" "p" nm path) asks for "Image Name" (nm) and not path name

Normally both are the same, but in my case not!

Link to comment
Share on other sites

but this is the Saved Path name and not the Reference Name?

 

I have the prompted list as names and not as saved path names and the difference between them is very little.

Link to comment
Share on other sites

They Really are different! When I run your code I get names which matches the "Saved Path" name.

The Reference Name is quite different:

 

Saved Path: "Gamba Post Mattress Installation Survey with cross profiles - 10.4923-DRA.DOC-4-3-0705 - Out Survey - Version Z01_TVW0101_Depth Colors.png" (I get this one with your code!)

Reference Name: "GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors"

 

The -image command asks for a image list which is the reference name!

 

Command: -IMAGE

Enter image option [?/Detach/Path/Reload/Unload/Attach] : p

Enter list of images for path modification: Gamba Post Mattress Installation Survey with cross profiles - 10.4923-DRA.DOC-4-3-0705 - Out Survey - Version Z01_TVW0101_Depth Colors.png

No matching image names found.

 

You really need the Reference Name:

 

Command: -IMAGE

Enter image option [?/Detach/Path/Reload/Unload/Attach] : p

Enter list of images for path modification: GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors

Image name: GAMBA POST MATTRESS INSTALLATION SURVEY WITH CROSS.9BD8B195-281A-4564-A981-5D3BA8CDF376_10.4923-DRA.DOC-4-3-0705_Z01_TVW0101_Depth Colors

Old path: Gamba Post Mattress Installation Survey with cross profiles - 10.4923-DRA.DOC-4-3-0705 - Out Survey - Version Z01_TVW0101_Depth Colors.png

Link to comment
Share on other sites

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...