Jump to content

_ColorOffsetV031 Unknown command "COLOROFFSETV031". Press F1 for help.


AM-AP

Recommended Posts

Hi there, I'm AM and new to the forum 

 

I'm creating a set of easy lisp routines for my team. I've loaded the following lisp file into AutoCAD and it works fine when typing the function ColorOffsetV031 into the command line within AutoCAD. However, when I try create a new command that will run the lisp with a macro like

^C^CColorOffsetV031

or

^C^C_ColorOffsetV031

so I can then add it to a ribbon/tab/tool palette, I get the following error:

"_ColorOffsetV031 Unknown command "COLOROFFSETV031".  Press F1 for help."

 

I'm honestly not sure what I'm doing wrong. I've tried different ways of loading the lisp file, from just dropping the file into AutoCAD, adding it to the Startup Suite, loading it as an application etc.

I've created 'buttons' like this before, and I feel so silly asking such a simple question; It's probably something really simple that I just can't pick up on... Even if someone can point me in the direction of a related post from someone else I would be very grateful :)

 

The lisp:

; Define the tool/function name and variables
(defun C:ColorOffsetV31 ( / EName EInfo EColor Group ans ansColor)
	(setvar "CMDECHO" 1)
	
	; Set the options for user choice
	(initget "Orange Red Yellow Green Cyan Blue Magenta White L-Grey")
	; Ask for user input on color for offset
	(setq ans (cond ((getkword "\nChoose offset object color [Orange/Red/Yellow/Green/Cyan/Blue/Magenta/White/L-Grey] or ENTER for Orange")) ("Orange")))
	; Set ansColor as input color
	(cond
		((= ans "Orange")	(setq ansColor 30))
		((= ans "Red")		(setq ansColor 1))
		((= ans "Yellow")	(setq ansColor 2))
		((= ans "Green")	(setq ansColor 3))
		((= ans "Cyan")		(setq ansColor 4))
		((= ans "Blue")		(setq ansColor 5))
		((= ans "Magenta")	(setq ansColor 6))
		((= ans "White")	(setq ansColor 7))
		((= ans "L-Grey")	(setq ansColor 8))
		; Should not happen but just here incase no input is given, set ansColor to BLACK
		(t					(setq ansColor 250))
	)
	
	;-----------------------------
	; Start OFFSET
	(command "OFFSET" pause)
	
	; Do the following with OFFSET
	(while (= 1 (logand 1 (getvar "CMDACTIVE")))
	
		(command pause)
	
		; While OFFSET command is on
		(while (= 1 (logand 1 (getvar "CMDACTIVE")))
	
			(command pause)
	
			; Set the current entity to be used as the last clicked entity
			(setq EName (entlast))
			; Get entity info
			(setq EInfo (entget EName))
			; If the colour of the object isn't known
			(if (not EColor)
	
				; Match ans to EColor
				(setq EColor ansColor)
	
			)
			; Change the colour
			(entmod (append EInfo (list (cons 62 EColor))))
	
		)
	)
	(setvar "CMDECHO" 0)
	(princ)
)

 

Here's a copy of the command itself too :)

 

Thanks,

 

AM

 

ColorOffsetV03-1 Command.gif

Link to comment
Share on other sites

why i try and stick with shorter command names or have a shortcut like

 

(defun C:ColorOffsetV31
   ...
)


(defun C:COV31 () (C:ColorOffsetV31)) ;only calls longer code

 

---edit

you might also like this option for picking a color.

 

(if (eq (setq ansColor (acad_truecolordlg 30)) nil)   ;acad_colordlg for just the 256 types
  (setq ansColor 250))
)

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

Updated the code a bit. if you where to offset multiple or both sides only one entity would change color. among other things.

 

;;----------------------------------------------------------------------------;;
;; Choose Color and offset
(defun C:ColorOffsetV31 (/ ansColor LastEnt en)
  (if (eq (setq ansColor (car (acad_truecolordlg 30))) nil)  ;acad_colordlg for just the 256 types
    (setq ansColor '(62 . 250))
  )
  (setq LastEnt (entlast))
  (command "OFFSET")
  (while (< 0 (getvar 'CMDACTIVE))
    (if (setq en (entnext LastEnt))
      (while en
        (if (eq (setq col (assoc 62 (setq ent (entget en)))) nil)
          (entmod (append ent ansColor))
          (entmod (subst ansColor col ent))
        )
        (setq en (entnext en))
      )
    )
    (command pause)
  )
  (princ)
)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Good morning/afternoon :) I'm just getting back into my routine after some extended leave, my apologies for not getting back to you sooner @mhupp/@pkenewell. Hope you had good winter/summer new years.

 

@pkenewell Much appreciated for spotting that simple mistake of an addition of '0'.

 

@mhupp That updated code you posted is much more elegant than what I was using previously! I've noticed the same issue when using your updated code, and my longer version:

 

At the moment, it modifies the DXF Group Code 62, the Index Color. However, if the object that has been selected has a True Color DXF Code 420 (I.e If the user has been using color books or just the True Color palette), then code does not change the color as the True Color value overrules the new Index Color... Now I could just change everything to append the object to the equivalent True Color, but then AutoCAD does not recognise/show the Index Color and only shows the 'True Color' number.

 

If you have any suggestions as to how to just remove the True Color Group Code, please let me know! I believe that would solve it, I'm just uncertain how to do it. Currently trying to figure it out.. Like I said, this is all pretty new. Probably something to do with 'vl-remove', but I haven't used it before. I will revisit again tomorrow!

 

Again, cheers for your help.

 

-AM

Link to comment
Share on other sites

@mhupp I added in the line 

(setq ent (vl-remove (assoc 420 ent) ent))

To your version, which has done the job, just removing the 420 group code premptively. The full code at the bottom. However, I've noticed another hiccup. If the object color is set to 'ByLayer', the offset line color will not change and I receive an error:

; error: bad list: (A number that depends on what color the user had inputted?)

In the old code, it would change the color regardless (Albeit sometimes a bit finnicky) but this new version does not. I'm working on it, but if you have any suggestions, let me know :)

 

-AM

 

(defun C:ColorOffsetV3TEST13 (/ ansColor LastEnt en ent col)
	(if (eq (setq ansColor (car (acad_truecolordlg 30))) nil)  ;acad_colordlg for just the 256 types
	  (setq ansColor '(62 . 250))
	)
	
	(setq LastEnt (entlast))
	(command "OFFSET")
	(while (< 0 (getvar 'CMDACTIVE))
	
		(if (setq en (entnext LastEnt))
			(while en
				(setq ent (entget en))
				(setq ent (vl-remove (assoc 420 ent) ent)) ; remove DXF Group Code 420 property if it exists
				(if (eq (setq col (assoc 62 ent)) nil)
					(entmod (append ent ansColor))
					(entmod (subst ansColor col ent))
				)
				(setq en (entnext en))
			)
		)
		(command pause)
	)
	(princ)
)

 

Edited by AM-AP
Link to comment
Share on other sites

By way of simple explanation, try this:

(ASSOC 62 (ENTGET(CAR (ENTSEL))))

 

which will give you the colour set by an entity. Try it on a coloured thing, that is say Red, and then try it on a line set to 'bylayer' colour...

 

 

 

scratch that idea, readig the code properly now..... will type a reply shortly

Edited by Steven P
Link to comment
Share on other sites

Right a better answer for you.... keep what I said handy though (you or others reading this), it is a dead useful debugging too with or without the assoc part.

 

MHUPP posted earlier - life is getting exciting for him - so forum time is limited while he does other good stuff, so apologies, you have the rest of us for now,

 

Right... short answer... CAD is a PITA! In an entity description / association list some items are easy going, will go anywhere in the list and some like to be in the right place (In AutoCAD anyway, not sure about BricsCAD). Colour code is one that likes to be in the same place every time.

 

If you do the (entget... ) thing above - without the assoc part on a coloured entity you'll see that '62' is often the 9th place in the list, just after '8' the layer code. If it isn't there then the entity is coloured 'bylayer' - but you just told me that part above.

 

So is that enough for you to work it out... if it is stop reading.... 

 

This is what I did to test I was giving a half decent answer. Using Lee Mac as a reference, 'Insert Nth' - a great little code

 

 

Something not quite right when it did a polyline - need an entupd.

 

(defun C:ColorOffsetV3TEST13 (/ ansColor LastEnt en ent col)
;;Sub Routines
  ;; Insert Nth  -  Lee Mac
  ;; Inserts an item at the nth position in a list.
  ;; x - [any] Item to be inserted
  ;; n - [int] Zero-based index at which to insert item
  ;; l - [lst] List in which item is to be inserted
  (defun LM:insertnth ( x n l )
    (cond
      (   (null l) nil)
      (   (< 0  n) (cons (car l) (LM:insertnth x (1- n) (cdr l))))
      (   (cons x l))
    )
  )
;; End Sub Routines

  (if (eq (setq ansColor (car (acad_truecolordlg 30))) nil)  ;acad_colordlg for just the 256 types
    (setq ansColor '(62 . 250))
  )

  (setq LastEnt (entlast))
  (command "OFFSET")
  (while (< 0 (getvar 'CMDACTIVE))
    (if (setq en (entnext LastEnt))
      (while en
        (setq ent (entget en))
        (setq ent (vl-remove (assoc 420 ent) ent)) ; remove DXF Group Code 420 property if it exists
        (if (eq (setq col (assoc 62 ent)) nil)
          (entmod (LM:insertnth ansColor 9 ent)) ;; insert eg. (62 . 250) in 9th position in the entity
;          (entmod (append ent ansColor)) ;; remove this - puts (62 . 250) at the end of the list.. no good
          (entmod (subst ansColor col ent)) ;; entity has a colour, replace that
        ) ; end if
        (setq en (entnext en))
      ) ; end while
    ) ; end if
    (command pause)
  ) ; end while
  (princ)
)

 

  • Like 2
Link to comment
Share on other sites

Morning @Steven P

 

Thanks for your input and letting me know about MHUPP. All the best @mhupp :) 

 

Haha I agree, from my limited experience, it's been a little PITA! LISP has been a lot of trial and error for me.

 

Ahh that works great! I think I had a bit of misunderstanding on the object properties, but I believe I have my head around it now- My understanding is the insertnth is doing the following.

If the object is 'ByLayer, then the object just doesn't have the '62' property at all. So, if that is the case then it will insert the new user chosen color property into that 9th position rather than just the end of the list. 

 

I noticed that the behavior of the lisp with polylines does work but only changes the color after finishing/ending the lisp. This behavior is very similar to how my old original code worked with the colors of some types of objects only changing after finishing the tool. But ah, not so big a problem really- It still works!

 

Cheers for your time Steven.

 

Now I need to work some more on 'deploying' it to colleagues in a custom tool palette via OneDrive.. Let's see how it goes

 

-AM

Edited by AM-AP
  • Like 2
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...