Jump to content

Recommended Posts

Posted
I have not looked at what you have posted still eating my eggs, i wanted to say Thanks to Lee Mac.

 

I went to your webpage and incorporated the screenpoint for DCL into my command it works great.

 

You're very welcome! Glad I could help :beer:

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

  • pman860507

    27

  • Lee Mac

    15

  • BlackBox

    14

Posted
A quick FYI, SelectionSets, like Entity Names and VLA-Objects, act like 'pointers' in that you don't have to reassign the variable when the data is manipulated, e.g.

 

(defun c:foo ( / en s1 s2 )
   (if (setq s1 (ssget "_:L"))
       (progn
           (setq en (entlast) s2 (ssadd))
           (command "_.copy" s1 "" "_non" '(0. 0. 0.) "_non" '(0. 0. 0.))
           (while (setq en (entnext en)) (ssadd en s2))
           (sssetfirst nil s2)
       )
   )
   (princ)
)

 

:wink:

 

you lost me on this. on a couple of things. i know a little about pointers in other languages but nothing in lisp. so this went right over my head. the other thing what does the _non do?

Posted

If you have 10 entities included in a selection set, then sslength = 10, as there is a pointer to each entity. Using (ssname ) provides access to the entity name of the pointer that correlates to said index of the selection set.

 

The "_non" temporarily ensures that no OSNAP will be used (thereby changing the coordinates), and *should* have been included this in my original code.

Posted

In the code posted below. im trying to figure out how it is working. and where exactly i need to incorp my code.

(while (setq en (entnext en)) (ssadd en s2))

do i need to pull all my variable out of Variable EN while in this while loop if so does it need to happen before or after the (ssadd en s2)

 

other thought.

 

I know that the (ssadd en s2) is added the entity to the variable S2 is where i need to point to which entity i want to use so example:

 

(setq ents2 (ssname s2 (setq 1))) ;will pull out the 2nd entity of s2.
(setq ents2 (entget ents2)) ;gets info out of ents2
(setq temp1 (cdr (assoc 1 ents2))) ;gets label 1 out of entity.

 

(defun c:foo ( / en s1 s2 )     (if (setq s1 (ssget "_:L"))         (progn             (setq en (entlast) s2 (ssadd))             (command "_.copy" s1 "" "_non" '(0. 0. 0.) "_non" '(0. 0. 0.))             (while (setq en (entnext en)) (ssadd en s2))             (sssetfirst nil s2)         )     )     (princ) )

Posted (edited)

another thing i am having an issue with this.

after it runs the dialog box i get the error.

 

Command: Error: bad argument type: fixnump: nil

 

I think its something to do with the dch variable its returning T i think its needs to be an integer.

(defun edit ()
 (cond((not(and
         (setq dcl (findfile "copy_blk.dcl"))    ;; Check for DCL file
         (< 0 (setq dch (load_dialog dcl)))  ;; Attempt to load it if found
       ))(princ "\n** DCL File not found **"))
   ((not (new_dialog "copy_blk" dch "" (cond ( *screenpoint* ) ( '(-1 -1) ))))
     (setq dch (unload_dialog dch))
     (princ "\n** Dialog could not be Loaded **"))
   (t
   (set_tile "text_edit" temp)
   (mode_tile "text_edit" 3)
   (action_tile "text_edit" "(setq text_edit $value)")
   (action_tile "cancel" "(setq ddiag 1)(done_dialog 0)")
   (action_tile "accept" "(setq ddiag 2)(sVars)(setq *screenpoint* (done_dialog 1))")
   (start_dialog)
   (unload_dialog dcl_id)))
   
 (cond 
 ((= ddiag 1)
   (setq newval temp)
   (princ "\n Command cancelled\n") (exit))
 ((= ddiag 2)
   (setq newval text_edit)
   (princ "\n Text Changed\n"))
   )
   (princ))

When i use this code it works find. i even got all the code for text in there to work. still have a little issues with others. ( the original)

 

(defun edit ()   (setq dcl_id (load_dialog "copy_blk.dcl"))   (if (not (new_dialog "copy_blk" dcl_id) ) (exit))   (set_tile "text_edit" temp1)   (mode_tile "text_edit" 3)   (action_tile "cancel" "(setq ddiag 1)(done_dialog 0)")   (action_tile "accept" "(setq ddiag 2)(sVars)(done_dialog 1)")   (start_dialog)   (unload_dialog dcl_id)      (if (= ddiag 1)     (progn      (setq newval temp1)     (princ "\n Command cancelled\n") (exit)))      (if (= ddiag 2)     (progn     (setq newval text_edit)     (princ "\n Text Changed\n")))     (princ))

 

edit:

okay its not the dch. i dont really know why its doing this. it runs the dcl file but then after you hit enter or cancel it comes up with that variable the ddiag variable gets set to 1 or 2 but it doesnt do the last part of the code.

Edited by pman860507
Posted

Other Issue:

 

(while (setq en (entnext en)) (ssadd en s2))

When i have an "attribute"/"INSERT" selected this returns nil.

 

which destroys the code.

Posted

I have [quickly] rewritten your code to the following:

 

(defun edit ( / dcl dch ddiag )
   (cond
       (   (not
               (and
                   (setq dcl (findfile "copy_blk.dcl"))
                   (< 0 (setq dch (load_dialog dcl)))
               )
           )
           (princ "\n** DCL File not found **")
       )
       (   (not (new_dialog "copy_blk" dch "" (cond (*screenpoint*) ('(-1 -1)))))
           (setq dch (unload_dialog dch))
           (princ "\n** Dialog could not be Loaded **")
       )
       (   t
           (set_tile    "text_edit" temp)
           (mode_tile   "text_edit" 3)
           (action_tile "text_edit" "(setq text_edit $value)")
           (action_tile "cancel" "(done_dialog 0)")
           (action_tile "accept" "(setq *screenpoint* (done_dialog 1))")

           (setq ddiag (start_dialog))
           (unload_dialog dch)

           (cond
               (   (= ddiag 0)
                   (setq newval temp)
                   (princ "\n Command cancelled\n")
               )
               (   (= ddiag 1)
                   (setq newval text_edit)
                   (princ "\nText Changed\n")
               )
           )
       )
   )
   (princ)
)

Notes:

 

** Didn't know what (sVars) was doing, so removed it.

 

** Variable 'temp' is undefined.

 

** You were not making use of the done_dialog exit flags.

 

** Avoid using the (exit) as this forces an error, instead use a conditional statement so that the program terminates naturally if a condition is not fulfilled.

 

** You were using (unload_dialog dcl_id) when the variable dcl_id isn't defined.

 

** Localise your variables!

 

From guessing at what you are trying to achieve, perhaps have a look at this.

 

Lee

Posted

Just read the first post of the thread - will look at that code now.

Posted

sVars was just this sorry it wasn't added in.

 

(defun sVars()
 (setq text_edit(get_tile "text_edit"))
 (princ))
 

but im guessing the the $value takes care of that.

 

the variable temp you get from the main lisp program which is the text that is in the object. i can add it back in.

 

I actually just started localizing my variables with this program reading another one of your tutorials so i dont have it completely down.

 

but you nailed it on what i wanted done you truly are awesome.

 

update:

so i took out the Svars from the main code. and it works great for DTEXT but still doesnt on the Attributes. returns nill

Posted
it's a lot cleaner now.

 

^^ Lee is the programming version of a mafia 'cleaner' - as in - the guy you trust to do the tough jobs, makes it look easy, then usually doesn't get anywhere near enough $$$ for the trouble. mafia.gifmafia.gif

Posted
^^ Lee is the programming version of a mafia 'cleaner' - as in - the guy you trust to do the tough jobs, makes it look easy, then usually doesn't get anywhere near enough $$$ for the trouble.

 

:lol: lmao cheers Renderman - the $$$ part is certainly true :P

 

 

 

Anyway, if I haven't misunderstood your intentions pman, give the following a try:

 

DCL File - save this as "copyedit.dcl"

 

copyedit : dialog { label = "Edit Value of Object"; initial_focus = "edit"; spacer;
 : edit_box { label = "Enter value:"; key = "edit"; edit_width = 75; alignment = centered; allow_accept = true; }
 spacer; ok_cancel;
}

 

LISP file:

 

([color=BLUE]defun[/color] c:CopyEdit ( [color=BLUE]/[/color] *error* _edit e1 e2 el en id pt ss st )

   [color=GREEN];;===============================================;;[/color]
   [color=GREEN];; Example  © Lee Mac 2011  -  www.lee-mac.com   ;;[/color]
   [color=GREEN];;===============================================;;[/color]

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 id) ([color=BLUE]unload_dialog[/color] id))
       ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg) [color=MAROON]"*BREAK,*CANCEL*,*EXIT*"[/color]))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]defun[/color] _edit ( dcl value [color=BLUE]/[/color] tmp )
       ([color=BLUE]cond[/color]
           (  ([color=BLUE]new_dialog[/color] [color=MAROON]"copyedit"[/color] dcl)
              ([color=BLUE]set_tile[/color] [color=MAROON]"edit"[/color] ([color=BLUE]setq[/color] tmp value))
              ([color=BLUE]action_tile[/color] [color=MAROON]"edit"[/color] [color=MAROON]"(setq tmp $value)"[/color])
              ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]start_dialog[/color])) ([color=BLUE]setq[/color] value tmp))
           )
       )
       value
   )

   ([color=BLUE]cond[/color]
       (   ([color=BLUE]<=[/color] ([color=BLUE]setq[/color] id ([color=BLUE]load_dialog[/color] [color=MAROON]"copyedit.dcl"[/color])) 0)
           ([color=BLUE]princ[/color] [color=MAROON]"\nDCL not Found."[/color])
       )
       (   ([color=BLUE]not[/color]
               ([color=BLUE]and[/color]
                   ([color=BLUE]setq[/color] ss
                       ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color]
                          '(
                               (-4 . [color=MAROON]"<OR"[/color])
                                   (0 . [color=MAROON]"MTEXT,TEXT"[/color])
                                   (-4 . [color=MAROON]"<AND"[/color])
                                       (0 . [color=MAROON]"INSERT"[/color]) (66 . 1)
                                   (-4 . [color=MAROON]"AND>"[/color])
                               (-4 . [color=MAROON]"OR>"[/color])
                           )
                       )
                   )
                   ([color=BLUE]setq[/color] pt ([color=BLUE]getpoint[/color] [color=MAROON]"\nBase Point: "[/color]))
               )
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color])
       )
       (   [color=BLUE]t[/color]

           ([color=BLUE]if[/color] ([color=BLUE]setq[/color] e1 ([color=BLUE]entlast[/color]) el e1)
               ([color=BLUE]while[/color] ([color=BLUE]setq[/color] e2 ([color=BLUE]entnext[/color] el)) ([color=BLUE]setq[/color] el e2))
               ([color=BLUE]setq[/color] el [color=BLUE]t[/color])
           )
           ([color=BLUE]command[/color] [color=MAROON]"_.copy"[/color] ss [color=MAROON]""[/color] [color=MAROON]"_non"[/color] pt [color=BLUE]pause[/color])

           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]equal[/color] e1 ([color=BLUE]entlast[/color])))
               ([color=BLUE]while[/color] ([color=BLUE]setq[/color] el ([color=BLUE]entnext[/color] el))
                   ([color=BLUE]setq[/color] en ([color=BLUE]entget[/color]  el)
                         st ([color=BLUE]assoc[/color] 1 en)
                   ) 
                   ([color=BLUE]if[/color] ([color=BLUE]member[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 en)) '([color=MAROON]"ATTRIB"[/color] [color=MAROON]"TEXT"[/color] [color=MAROON]"MTEXT"[/color]))
                       ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 (_edit id ([color=BLUE]cdr[/color] st))) st en))
                   )
               )
           )
       )
   )
   ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 id) ([color=BLUE]unload_dialog[/color] id))
   ([color=BLUE]princ[/color])
)

Posted

I agree. he is pretty awesome.

 

here is my updated code that works perfect on everything but block attributes. i might have done something wrong in the code.

 

Also what does the t do in the calling of the dcl part of the code that Lee uses.

 

(defun edit ( / dcl dch ddiag )
   (cond
       (   (not
               (and
                   (setq dcl (findfile "copy_blk.dcl"))
                   (< 0 (setq dch (load_dialog dcl)))
               )
           )
           (princ "\n** DCL File not found **")
       )
       (   (not (new_dialog "copy_blk" dch "" (cond (*screenpoint*) ('(-1 -1)))))
           (setq dch (unload_dialog dch))
           (princ "\n** Dialog could not be Loaded **")
       )
       (   t
           (set_tile    "text_edit" temp)
           (mode_tile   "text_edit" 3)
           (action_tile "text_edit" "(setq text_edit $value)")
           (action_tile "cancel" "(done_dialog 0)")
           (action_tile "accept" "(setq *screenpoint* (done_dialog 1))")

           (setq ddiag (start_dialog))
           (unload_dialog dch)

           (cond
               (   (= ddiag 0)
                   (setq newval temp)
                   (princ "\n Command cancelled\n")
               )
               (   (= ddiag 1)
                   (setq newval text_edit)
                   (princ "\nText Changed\n")
               )
           )
       )
   )
   (princ)
)
 

(defun C:copy_blk (/ en2 eData enlist2 newval ss typ temp)
 (vl-load-com)
 (defun *Error* (Msg)
(cond ((member Msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "Error: " Msg))
(princ "\nRestoring System Variables ")
(terpri))) 
(princ))
 
 (if (setq ss (ssget "_:L"
                     '((-4 . "<OR")
                       (-4 . "<AND")
                       (0 . "INSERT")
                       (66 . 1)
                       (-4 . "AND>")
                       (0 . "MTEXT,TEXT")
                       (-4 . "OR>"))))
       (progn
           (setq en (entlast) s2 (ssadd))
           (command "_.copy" ss "" pause pause)
           (while (setq en (entnext en)) (ssadd en s2))
           (setq INDEX -1 COUNT 0)
           (while (setq en1 (ssname s2 (setq INDEX (1+ INDEX))))
           (setq enlist(entget en1))
           (setq blkType(cdr(assoc 0 enlist)))
           (if (= blkType "INSERT")                                                       
           (progn
               (if(= (cdr(assoc 66 enlist)) 1)                                                
               (progn
                   (setq en2(entnext enlist))                                                       
                   (setq enlist2(entget en2)) 
                   (setq temp (cdr (assoc 1 enlist2)))
                   (edit)
                   (setq enlist2 (subst (cons 1 newval)(assoc 1 enlist2)enlist2))
                   (entmod enlist2)))))
     
(if (or(= blkType "TEXT")(= blkType "MTEXT"))
(progn
   (setq temp (cdr (assoc 1 enlist)))
   (edit)
   (setq enlist (subst (cons 1 newval)(assoc 1 enlist)enlist))
   (entmod enlist)))
           (sssetfirst nil s2)
       )
   ))
   (princ))

Posted

Sorry i didnt see you reply Lee it was exactly what i was trying to do. i envy you.

 

so as im reading though your code Im completely amazed by it. your doing things i never knew you could. i love how you incorporated the dialog box within the to change the entity. (didnt know that was possible).

 

really all i can say is WOW!

Posted
Sorry i didnt see you reply Lee it was exactly what i was trying to do. i envy you.

 

Not a problem pman, you're very welcome :)

 

so as im reading though your code Im completely amazed by it. your doing things i never knew you could. i love how you incorporated the dialog box within the to change the entity. (didnt know that was possible).

 

You mean this line?

 

([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 (_edit id ([color=BLUE]cdr[/color] st))) st en))

This is only possible since I have engineered the '_edit' function to always return a string, even if the user hits cancel. Its not ideal since the object always get updated even if the string is unchanged, but I didn't spend too much time on it.

 

Looking back at it now, I would probably rewrite the '_edit' function to return nil if the user presses cancel, then test for a non-nil return before updating the entity.

 

really all i can say is WOW!

 

Cheers mate :beer:

  • 2 weeks later...
Posted

([color=BLUE]not[/color]                 ([color=BLUE]and[/color]                     ([color=BLUE]setq[/color] ss                         ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color]                            '(                                 (-4 . [color=MAROON]"<OR"[/color])                                     (0 . [color=MAROON]"MTEXT,TEXT"[/color])                                     (-4 . [color=MAROON]"<AND"[/color])                                         (0 . [color=MAROON]"INSERT"[/color]) (66 . 1)                                     (-4 . [color=MAROON]"AND>"[/color])                                 (-4 . [color=MAROON]"OR>"[/color])                             )                         )                     )                     ([color=BLUE]setq[/color] pt ([color=BLUE]getpoint[/color] [color=MAROON]"\nBase Point: "[/color]))                 )             )             ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color])         )

 

LEE I was looking at this code and i was trying to understand this part.

 

the cond statement above it is letting it run if the dcl file is loaded.

what i dont understand is the not statement. what do i need to edit to add another line of code.

 

i was thinking about adding a keyword in the getpoint statement. using

 

(initget "Multiple")

 

but i cant get it to work.

Posted

NOT will verify whether an expression evaluates to nil, hence it can be used to 'negate' a logical expression, for example:

 

(not nil) = T
(not T) = nil

 

Now have a read of this about AND:

 

http://www.cadtutor.net/forum/showthread.php?61672-Block-Attributes&p=419102&viewfull=1#post419102

 

If, after reading the above you understand the logic, note that the initget function will always return nil.

 

That should point you in the right direction :thumbsup:

Posted

that actually explains a lot.

 

When i added (initget "Multiple") it returns nil so it kills it.

Posted

again thanks for the link Lee. i got the program to run with a Multiple options. It works kind of like copy does you just use the multiple option before you select the basepoint.

Posted

Excellent pman, glad to hear it :thumbsup:

 

I find the information sticks better when you have solved something for yourself :)

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