Jump to content

Recommended Posts

Posted

Hi!

 

I am trying to figure out how to make a lisp that does the following:

 

1. Check if a profile with a given name (eg. Engineering) exist in AutoCAD

2. If the profile exist it should be set active

3. If the profile does not exist the active profile should be copied and named "Engineering" and set active.

 

I have tried to put together some code from several sites and I have this:

 

(vl-load-com)

;get profiles from AutoCAD
(vlax-invoke-method acadProfiles 'GetAllProfileNames 'profilelist)
;convert the list
(setq profilelist (vlax-safearray->list profilelist))
;check if the profile exist
(if (not (member "Engineering" profilelist))
;if it does'n exist
(progn
   ;copy active profile and rename to "Engineering"
  (vlax-invoke-method acadProfiles 'CopyProfile actProfile "Engineering")
 )
)

;set "Engineering" as active profile
(vla-put-ActiveProfile acadProfiles "Engineering")

 

BUT, it doesn't work.

 

Can anyone help me out?

Posted (edited)

Welcome to CadTutor :)

 

Hope this would help you with it .

 

(defun c:Test (/ Pfs lst)
 ;;--- Tharwat 25. April. 2013 ---;;
 (setq Pfs (vla-get-Profiles
             (vla-get-Preferences (vlax-get-acad-object))
           )
 )
 (vla-GetAllProfileNames Pfs 'lst)
 (if (not
       (member "Engineering" (vlax-safearray->list lst))
     )
   (progn
     (vla-copyprofile
       Pfs
       (vla-get-activeprofile Pfs)
       "Engineering"
     )
     (vla-put-activeprofile Pfs "Engineering")
   )
   (vla-put-activeprofile Pfs "Engineering")
 )
 (princ)
)
(vl-load-com)

Edited by Tharwat
Posted

Thank you for your fast reply. But I couldn't get it to work. There are no errors in AutoCAD but it doesn't copy the current profile (which is "Unnamed Profile").

Posted

Actually it should do , did you check the profiles tab in the options ?

Posted

Try this:

(defun c:setprofile ( / lst prf prn )
   (setq prn "Engineering"
         prf (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
   )
   (vla-getallprofilenames prf 'lst)
   (setq lst (vlax-safearray->list lst))
   (if (member prn lst)
       (vla-put-activeprofile prf prn)
       (progn
           (vla-copyprofile prf (getvar 'cprofile) prn)
           (vla-put-activeprofile prf prn)
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

I wouldn't assume that the current profile will always be first in the list returned by the getallprofilenames method.

Posted
Lee , May I know what's the new with your code to mine ?

 

If I may... Consider the difference between (car nm), and (getvar 'cprofile), in the context of Lee's ending comment.

Posted
If I may... Consider the difference between (car nm), and (getvar 'cprofile), in the context of Lee's ending comment.

 

However if the Auto-Cad session has only one profile or more the (car nm) would return a name of a profile and would copy one

of them and activate it as it's been asked by the OP . :unsure:

Posted
However if the Auto-Cad session has only one profile or more the (car nm) would return a name of a profile and would copy one

of them and activate it as it's been asked by the OP . :unsure:

 

But the OP states:

3. If the profile does not exist the active profile should be copied and named "Engineering" and set active.

 

Hence my comment:

I wouldn't assume that the current profile will always be first in the list returned by the getallprofilenames method.
Posted
Actually it should do , did you check the profiles tab in the options ?

 

Checked in the profiles tab but there is only Unnamed profile that is listed. I have also tried it after adding other profiles but nothing seams to happen.

Posted

As Lee Mac pointed out I need it to be active profile that's being copied. This is something I'm going to you for about 20-30 users and I don't know exactly how their AutoCAD setup is I want to make a copy of their current settings and just add some support paths, tool palettes and so on.

Posted

This is what happens:

 

Command: (load setprofile)
; error: bad argument type: stringp nil

Posted
This is what happens:

 

Command: (load setprofile)
; error: bad argument type: stringp nil

 

Assuming you have saved the file as 'setprofile.lsp' in your AutoCAD Support Path, you can load it using:

(load "setprofile")

Note the quotation marks!

Posted

Had forgotten about the quotation marks. But I still can't get it to work. No new profiles show up.. I have tried it on both AutoCAD 2012 and 2013.

Posted
Had forgotten about the quotation marks. But I still can't get it to work. No new profiles show up.. I have tried it on both AutoCAD 2012 and 2013.

 

I am not sure if you are running the lisp code correctly as it's clear from your last reply , so here is a way about how to run the code .

 

* Open Autocad and type in the command line vlide and start a new file .

* Copy the codes that I posted for you and paste them in the new file in Vlide and save the file with the name test .

* Go back to autocad and type appload or ap and select the lisp file that you have just saved earlier and press load to load the lisp file .

* Finally type test in the command line to invoke the function and you must see the changes on the screen and after that type options , then

go to profile tab to see the new profile "engineering" that must be created .

 

 

Try it and let me know .

 

Hope this helps :)

Posted

That worked!

I had loaded the file but never actually invoked the function. My bad :oops:

 

Thanks guys for your help :)

Posted
That worked!

I had loaded the file but never actually invoked the function. My bad :oops:

 

Thanks guys for your help :)

 

 

Excellent , you're welcome . :)

Posted

I have one more question about this. The script provided works if I load it and start the function from the command line after a drawing has been opened. Is it possible to make this work from the acad.lsp file? My goal is to distribute the acad.lsp to all user on a network and that way automatically run this every time they start AutoCAD.

Posted
Is it possible to make this work from the acad.lsp file? My goal is to distribute the acad.lsp to all user on a network and that way automatically run this every time they start AutoCAD.

 

In your acad.lsp type:

(load "setprofile.lsp" "Unable to load setprofile.lsp")
(if c:setprofile (c:setprofile))

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