Jump to content

Recommended Posts

Posted

Hi Ronjonp,

 

I won't be able to check this until tomorrow when I'm back in work unfortunately. But maybe you can tell me something in the mean time. Will this completely change the path or replace part of the xref path? This is the reason that I wanted to use the redir command originally. After _projects in the path name comes the project number followed by some sub directory names. The part I want to swap is common to all xrefs and images and is found only at the start of the path.

 

Thanks

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • feargt

    16

  • Lee Mac

    7

  • ReMark

    6

  • ronjonp

    4

Posted

It will only replace part of it :) ....give this a try:

 

(alert (vl-string-subst "\\\\SERVER101\ACAD\\_Projects" "B:\\_Projects" "B:\\_Projects\\myfolder\\123\\abc"))

Posted
It will only replace part of it :) ....give this a try:

 

(alert (vl-string-subst "\\\\SERVER101\ACAD\\_Projects" "B:\\_Projects" "B:\\_Projects\\myfolder\\123\\abc"))

 

Hi ronjonp,

 

many thanks again for your time on this.

 

So I've tested this and I cannot get it to work.

When I test it I get this

 

 

Befehl: vlisp

b:\_projects\P101\standard\xref_plankopf.dwg

ACADDOC.LSP loaded....

 

This is what I am using.

 

(defun rjp-changexrefpath (path1 path2 / newpath xrpath)

(vl-load-com)

(vlax-map-collection

(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))

(function

(lambda (x)

(if (= (vla-get-isxref x) :vlax-true)

(progn (setq xrpath (strcase (vlax-get x 'path) t))

(if (and (vl-string-search (strcase path1 t) xrpath)

(setq newpath (vl-string-subst path2 path1 xrpath))

(findfile newpath)

)

(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list x newpath)))

(princ (strcat "\n**OLD path found but was not changed!\n" xrpath))

(princ (strcat "\n" newpath))

)

)

)

)

)

)

)

(princ)

)

(rjp-changexrefpath "B:\\_Projects" "\\\\SERVER101\\acad\\_Projects")

 

I've tried running it, then saving and reopening but the path does not change.

 

 

I cannot see why it does not work.

 

(alert (vl-string-subst "\\\\SERVER101\ACAD\\_Projects" "B:\\_Projects" "B:\\_Projects\\myfolder\\123\\abc"))

 

I tried this and works as it should.....so I'm a bit stumped at the mo.

 

 

Can anyone else see why it doesn't work for me?

Posted

Try changing this:

 

(rjp-changexrefpath "B:\\_Projects" "\\\\SERVER101\\acad\\_Projects") 			 		

 

to this:

 

(rjp-changexrefpath "\\\\SERVER101\\acad\\_Projects" "B:\\_Projects") 			 		

Posted

Hi Lee,

 

I tried that but with no success.

 

From the original post by ronjonp it sounds as though it was working for ronjonp.

 

 

(alert (vl-string-subst "\\\\SERVER101\ACAD\\_Projects" "B:\\_Projects" "B:\\_Projects\\myfolder\\123\\abc"))

 

From this quote it appears that the paths are in the correct order with

 

(rjp-changexrefpath "B:\\_Projects" "\\\\SERVER101\\acad\\_Projects")

Posted

Ok for now I have a solution, Whether it is the optimal solution or not I cannot say.

 

But basically from the acaddoc.lsp file, I am now calling a script file which runs the Redir command.

 

This works now. Thanks for all the input but if anyone does have a better solution please share it.

 

Thanks

Posted

Sorry for the late response...will you give this a try and let me know if it works for you. I think the issue before was related to strcase :shock:

 

(defun rjp-changexrefpath (path1 path2 / newpath xrpath)
 (vl-load-com)
 (vlax-map-collection
   (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (function
     (lambda (x)
       (if (= (vla-get-isxref x) :vlax-true)
         (progn (setq xrpath (strcase (vlax-get x 'path) t)
                      path1  (strcase path1 t)
                      path2  (strcase path2 t)
                )
                (if (and (vl-string-search path1 xrpath)
                         (setq newpath (vl-string-subst path2 path1 xrpath))
                         (findfile newpath)
                    )
                  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list x newpath)))
                    (princ (strcat "\n**OLD path found but was not changed!\n" xrpath))
                    (princ (strcat "\n" newpath))
                  )
                )
         )
       )
     )
   )
 )
 (princ)
)

Posted

Hi ronjonp,

 

I certainly will give it a shot, but it will be Monday I'd say before I get a chance to.

Thanks for following it up. Will give you the feedback as soon as I try it.

 

Thanks

Posted

So I tried that out and it works. But as you said the result is only visible in the Classic Xref dialogue box.

Unfortunately I don't know any VB, VBA so I do not know how to modify this so that it works on images too.

 

For now I'll leave it using my script file. It seems to be working well.

 

But I am considering also redefining the Save command so that it also runs the script.

 

That way it will work on both new Xref files which are created in a short space of time and require no modification (ie. Ortho photos. after theý are created they do not need to be opened again and a are only used as an xref)and also will work on existing drawings in older projects.

 

Thanks again to everyone for their help

  • 6 months later...
Posted

Hey there,

 

I've got the same kind of problem here with replacing a server. I think this a good VBA to renew the path to another path:

 

Public Sub Rename_XPath()
   Dim tempBlock As AcadBlock
   For Each tempBlock In ThisDrawing.Blocks
       If tempBlock.IsXRef Then
           ' Block is an external reference
           If Left(tempBlock.Path, 5) = "xxxx" Then 'Checks the first 5 characters if the x-ref has a old path
               tempBlock.Path = "[color=red]NEW PATH[/color]" & tempBlock.Name & ".dwg"
               tempBlock.Reload
           End If
       End If
   Next
End Sub

 

This looks much more easier to me.... :oops: Please comment! :)

  • 5 weeks later...
Posted

Why not use the code already given to you? :huh:

Posted
I'm more a VBA-dude then a Lisp-er o:)

 

I would be inclined to be more of a LISP-dude than VBA-er, seeing as VBA is getting phased out... o:)

Posted
I would be inclined to be more of a LISP-dude than VBA-er, seeing as VBA is getting phased out... o:)

 

Speeking of that. Can you tell me anything about the phasing out of VBA? And how it's supported in future autocad version? Will there be another way to program things for your own?

 

Probably there is something on the internet about that but I wasn't able to find anything concrete. o:)

Posted
Can you tell me anything about the phasing out of VBA? And how it's supported in future autocad version? Will there be another way to program things for your own?

 

Here is a good thread detailing it:

http://www.cadtutor.net/forum/showthread.php?t=32857

 

Also, in it's no longer installed on 2010:

 

vbaide.png

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