Jump to content

New file LISP


Bloodhurt

Recommended Posts

Hello,

 

I'm creating a lisp where one part is about opening a new file.

 

When I'm using the command line ("new" "") it's working (with filedia "0), however when I'm trying to write same with with a simple code:

 

(defun c:nowy()
(command "new" "")
)

it doesn't.

Command: NOWY

new

Command: NOWY Unknown command "NOWY". Press F1 for help!

Command: nil

I have no idea why... Please if you could help me I would appreciate that (note: I don't want a new defun, cause I still don't know how to connect lisps together :P just a part of the code ^^)

Link to comment
Share on other sites

Thank you, it solved a problem, however a new one appeared... it continues working on a old file instand of the new one :P. Basicly the lisp should work like this:

 

Copy with base point -> select text (to use it as a name to save a new file) -> open new file -> paste with 0,0 and center -> save as dxf (with a name from the origin file) -> close.

 

;;please make it works!
(defun c:test1 ()
			
			
(vl-load-com)

;;Copy with a base point

(progn
	(command "copybase" (setq pnt1 (getpoint "\nZaznacz lewy dolny rog ramki ISO: ")) (ssget) "")
)

;;Point the new dxf name

	(SETQ Match (NENTSEL "\nSelect Attribute or Text: "))
(command "chprop" Match "" "color" "t" "100,100,100" "")
(IF (= Match NIL)(ALERT "Please Select Attribute or Text..."))

(IF (/= NIL Match)
(PROGN
(SETQ Match (ENTGET (CAR Match)))
)
)



;;open new file


  (vla-activate (vla-add (vla-get-documents (vlax-get-acad-object)) templateName))

its all working up to that moment. The farther part also works but in the old file :P

 

;;paste at 0,0 and center


(command "pasteclip" "0,0")
(command "zoom" "a")

;;save as dxf

(command "filedia" "0")
(IF(SETQ Text(CDR(ASSOC 1 Match)))
(command "saveas" "dxf" "v" "r12" "" Text)
)
(command "filedia" "1")
(command "purge" "a" "*" "n")
(command "close" "n")	


)

 

Also if you could tell me - where I can learn how to connect 2 and more lisps together :D Cause I'm pretty sure it would be easier to connect 4 seperated lisps I had created (copy, new, paste, save) than trying to write a one long code...

 

Thank you for your help,

cad_lisps_noobish_writer :D

Link to comment
Share on other sites

It is possible to call (load) a lisp file from another lisp file. Suppose you have a lisp file called a.lsp , then from this lisp file you can use (load "b.lsp") , where maybe you have a function called c:lisp-b , and then use (c:lisp-b) to run it. Afterwards the original function from a.lsp will resume. But when you open or create another drawing your lisp routine will lose its focus. You can use bb-set and bb-ref to pass values between drawings or use a script file. Haven't tried your lisp's yet but if a have some spare time later on I will have a look at it or maybe someone else can have a go.

 

 

gr. Rlx

Link to comment
Share on other sites

Thank you, it solved a problem, however a new one appeared... it continues working on a old file instand of the new one :P. Basicly the lisp should work like this:

 

Copy with base point -> select text (to use it as a name to save a new file) -> open new file -> paste with 0,0 and center -> save as dxf (with a name from the origin file) -> close.

 

;;please make it works!
(defun c:test1 ()
               
               
   (vl-load-com)

;;Copy with a base point
   
   (progn
       (command "copybase" (setq pnt1 (getpoint "\nZaznacz lewy dolny rog ramki ISO: ")) (ssget) "")
   )

;;Point the new dxf name

       (SETQ Match (NENTSEL "\nSelect Attribute or Text: "))
(command "chprop" Match "" "color" "t" "100,100,100" "")
(IF (= Match NIL)(ALERT "Please Select Attribute or Text..."))

(IF (/= NIL Match)
(PROGN
(SETQ Match (ENTGET (CAR Match)))
)
)

   

;;open new file

   
  (vla-activate (vla-add (vla-get-documents (vlax-get-acad-object)) templateName))

its all working up to that moment. The farther part also works but in the old file :P

 

;;paste at 0,0 and center
   
   
   (command "pasteclip" "0,0")
   (command "zoom" "a")

;;save as dxf

(command "filedia" "0")
(IF(SETQ Text(CDR(ASSOC 1 Match)))
(command "saveas" "dxf" "v" "r12" "" Text)
)
(command "filedia" "1")
(command "purge" "a" "*" "n")
(command "close" "n")    

   
)

Also if you could tell me - where I can learn how to connect 2 and more lisps together :D Cause I'm pretty sure it would be easier to connect 4 seperated lisps I had created (copy, new, paste, save) than trying to write a one long code...

 

Thank you for your help,

cad_lisps_noobish_writer :D

 

 

 

 

Just had a quick look (have to go to meeting soon) , but first you have to get the text value of the attribute you select (and test if you have selected a attribute in the first place) , suppose you have one selected , entity called E , then use (setq txt (cdr (accoc 1 (entget e)))) to get the text value , then use (bb-set 'name txt) and then in the next drawing you can recall the text value with (bb-ref 'name)

 

 

Will check on you later but have to run now...

 

 

gr. Rlx

Link to comment
Share on other sites

Ok thanks. Right now I got stuck and have no clue what to do next. Also there is some error which I can't solve.

 

Also I will paste all 4 codes I wrote (and/or found :P) which are working seperatly. Maybe connecting them would be easier than rewriting them:

 

Copy with base point


(defun c:kopiowanie ()
(progn
	(command "copybase" (setq pnt1 (getpoint "\nZaznacz lewy dolny rog ramki ISO: ")) (ssget) "")
)

;;Point name

(SETQ Match (NENTSEL "\nSelect Attribute or Text: "))
(command "chprop" Match "" "color" "t" "100,100,100" "")
(IF (= Match NIL)(ALERT "Please Select Attribute or Text..."))
(IF (/= NIL Match)
	(PROGN
		(SETQ Match (ENTGET (CAR Match)))
	)
)
)

 

Open new file (found)

(defun c:OpenMyDwg ( / _OpenDwg )
 (defun _OpenDwg  (dwg readOnly / f oDwg)
 ;; RenderMan, CADTutor.net
 ;; Example: (_OpenDwg "FilePath\\FileName.dwg" T)
 (vl-load-com)  
 (if (and (setq f (findfile dwg)) (/= 1 (getvar 'sdi)))
   (vla-activate
     (vla-open (vla-get-documents (vlax-get-acad-object))
               f
               (cond ((= T readOnly) :vlax-true)
                     ((:vlax-false)))))
   (cond (f (prompt "\n** Command not available in SDI mode ** "))
         ((prompt (strcat "\n** \""
                          (strcase (vl-filename-base dwg))
                          "\" cannot be found ** "))))))
 
 (_OpenDwg
   "D:\\TEST.dwg"
   T)
 (princ))

 

Paste at 0,0

(defun c:wklej ()
(command "pasteclip" "0,0")
(command "zoom" "a")
)

 

Save as dxf (with name from copy part)

(defun c:zapisz ()
(command "filedia" "0")
(command "purge" "a" "*" "n")
(command "saveas" "dxf" "v" "r12" "" Text)
(command "filedia" "1")
(command "close" "n")	
)	

 

I'm 90% sure it's all wrong... however! I gave my best shot at trying to solve that :P

Best regards!

Link to comment
Share on other sites

ok , short recess before next meeting , but like to keep busy ;-)

 

 

if I understand correctly all you want to do is to write some entities to a dxf file? So why not use the object parameter?

 

 

have a look at this

 

 



(defun c:write-dxf ( / tstdir ss e edat )
 (setvar "filedia" 0)
 (setq tstdir "c:/temp/")
 (princ "\nSelect objects to write to dxf file")
 (if (and
(setq ss (ssget))
(setq e (car (nentsel "\nselect attribute with for dxf filename")))
(setq edat (entget e))
(eq (cdr (assoc 0 edat)) "ATTRIB"))
   (command "dxfout" (strcat tstdir (cdr (assoc 1 edat))) "obj" ss "" 16))
 (setvar "filedia" 1)
 (princ)
)


 

 

I test for attribute and selection set but I dont test for whatever string is in your attribute , so i assume you know what you're doing

 

 

Well back 2 work 4 me , hope 2 be back soon but am affraid not :-(

 

 

gr.Rlx

Link to comment
Share on other sites

To be honest I'm not sure what I'm doing ;) I'm just a designer which wants to make his, and my co-workes, life easier :P

 

The idea for this lisp was to create a .dxf file with few objects (and texts inside) centered from the original .dwg file. Right now we're doing it manualy which takes time. So I wrote 4 seperate lisps (posted above) which are working quiet well, but than problems appeared when I tried to connect them together :P.

 

The code you posted seems to be kinda what I need, i think :D

 

So just to be clear - here is what I need from this lisp:

1. Select objects and copy with a base point from the origin .dwg

2. Open new file (or .dxf or whatever), past the objects and the 0,0 coords, center the view (this is important (double mouse click :P))

3. Save the file in .dxf format with the name selected at the origin .dwg and close it (it is also possible to copy the name from the origin .dwg to the new file and after choseing the name deleting it, but the view ALWAYS has to be centered)

 

Gonna search the internet for some more solutions, but I realy appreciate your help ;) You're my hero! :D

Link to comment
Share on other sites

Try if this is what you need :

 

Bloodhurt.LSP

 

It uses dwgprefix to put the drawing with the objects you select in (the same folder as the master drawing).

 

You first select a basepoint for your objects , then the object to be written to file (it then wblocks these objects to a drawing with the name it finds in the attribute you select). After that it opens that drawing (via a script) and moves all object to 0,0 and puts the insertion base of that drawing to 0,0 , zooms extents and saves the drawing.

 

sdi must be 0

 

gr. Rlx

Edited by rlx
Link to comment
Share on other sites

Morning @rlx

 

Thank you for this lsp, You're great! However... it has unknown for me bug :P at part of selecting atribute for the file name i has an error:

select attribute with text for filename; error: unsupported argument type nil
. And I have no clue whats the problem, for the last 2h I was trying different things to find out the solution, but I failed hard ;(

 

btw. wblock was my second idea for this lsp :D

 

//OK, I'm 90% sure this is just some stupid mistacke I'm doing with it... I checked it 3 times, checked every command and it's just too simple to have some serious mistacke.. :P

Edited by Bloodhurt
Link to comment
Share on other sites

Could you upload (part of) the drawing / block with attribute you are having trouble with?

 

 

btw... i have autocad 2012 here so i you have a higher version please save it as a 2012 file format gr. rlx.

 

 

btw btw if you type (entget (car (nentsel))) and select the attribute what does it show , is it an attrib or something else?

Edited by rlx
Link to comment
Share on other sites

Sorry for not replying.. didn't see there was a 2nd page of this thread :D

test.jpg

So basicly as you can see I have something like this, and I need to select everything inside with the base point in the bottom left corner of the white rec. and save it as a dxf R12.

 

I'm using ZWCAD 2015 (some co-workers have 2014).

 

// Right now I wrote some other lisp for that, also with wblock command, but way more easier and simpler than yours :P :

(defun c:DXFY ()
(command "filedia" 0)
;; dxf name
(SETQ Match (NENTSEL "\nSelect Attribute or Text: "))
(command "chprop" Match "" "color" "t" "100,100,100" "")
(IF (= Match NIL)(ALERT "Please Select Attribute or Text..."))
(IF (/= NIL Match)
(PROGN
(SETQ Match (ENTGET (CAR Match)))
)
)
(SETQ Text(CDR(ASSOC 1 Match)))
;;copy base

(command "copy" (ssget) "" (setq pnt1 (getpoint "\nZaznacz lewy dolny rog ramki ISO: ")) pnt1)
(command "select" "previous" "")
(command "group" "" "1234" "" "previous" "" )
(command "move" "group" "1234" "" pnt1 "0,0")
;;wblock function 
(command "-wblock" Text "yes"  pnt1 "group" "1234" "")
;;defun ends
(command "group" "e" "1234")
(command "filedia" 1)
)

 

I have 2 problems with it:

1. I need to add some loop at selecting attribute at File name so it won't proceed with out it (right now it does :P)

2. The dxf file format isn't R12

 

and I'm going to add 1 more thing that zooms the view at the selected objects, but that won't be a problem I guess ;)

Link to comment
Share on other sites

Ok, I've solved 2nd problem with the file format and added the zoom part ;) Just the loop thing and I'm at home ;D

Edited by Bloodhurt
Link to comment
Share on other sites

 (defun c:XFY ()  
   (command "filedia" 0)  ;; dxf name 
   (while (SETQ Match (NENTSEL "\nSelect Attribute or Text: "))
        (progn
            (command "chprop" Match etc etc
        )
    )
    (command "filedia" 1)
 )

 

gr. Rlx

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