TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: nlanum on July 01, 2010, 06:56:56 PM

Title: Help Desperately Needed
Post by: nlanum on July 01, 2010, 06:56:56 PM
I have some custom tools that were developed for ACAD 2007.

When we upgraded to ACAD 2010, the tools did not work anymore.
I paid a company to make it work for ACAD 2010 and everything was working fine. Now, we have upgraded to ACAD 2011 and the tools do not work anymore. I get an error stating "incompatible autocad version". Will someone please look at the following code and see if we can make it work for ACAD 2011.

These are the only changes that I can see that were made to make this work for ACAD 2010. I need this to work in ACAD 2011.

Thanks in advance.

Norm
Code: [Select]
--------------------------------
;;; **** Replace function in VLX for compatability with 2010+
(defun ZF_GET-ACADCOLOR ()
  (VL-LOAD-COM)
  (setq ZF_ACADCOLOR
(vla-GetInterfaceObject
   (ZF_GET-ACAD-OBJECT)
   (strcat "AutoCAD.AcCmColor."
   (itoa (ATOI (GETVAR "ACADVER")))
   )
)
  )
)
;;; **** Additional function for Ribbon deployment
(defun setupInsReactor (props)
  (setq lke (entlast))
  (setq insEnd:cmdreactor
   (vlr-Command-Reactor
     nil
     '((:vlr-CommandEnded . InsertDynamic))
   )
insCan:cmdreactor
   (vlr-Command-Reactor
     nil
     '((:vlr-commandCancelled . killReactor))
   )
insFail:cmdreactor
   (vlr-Command-Reactor
     nil
     '((:vlr-commandCancelled . killReactor))
   )
Savedprops    props
  )
  (prompt "\nReactors setted.")
)
(defun EDIINSERT (lay blk scl ang props)
  (EDISETLAYER lay)
  (if props
    (setupInsReactor props)
  )
  (command "-insert" blk)
  (if (= "*" (substr blk 1 1))
    (progn
      (command (setq ip (getpoint)))
      (if scl
(command scl)
(command (getdist ip))
      )
      (if ang
(command ang)
(command (getangle ip))
      )
    )
    (progn
      (if scl
(command "S" scl)
      )
      (if ang
(command "R" ang)
      )
    )
  )
)

(defun EDISETLAYER (lay)
  (if (not (tblsearch "layer" lay))
    (progn
      (prompt (strcat "*** Layer " lay " does not exist! ***"))
      (command "-layer" "m" lay "")
    )
  )
  (command "-layer" "s" lay "")
)
(defun asmi-LayersStateRestore (StateList)
  (foreach lay StateList
    (vla-put-Lock (car lay) (cadr lay))
  )
  (princ)
)
; Insert Call Back
(defun InsertDynamic (callReact cmdArgs)
  (if (or (= (car cmdArgs) "INSERT")
  (= (car cmdArgs) "-INSERT")
      )
    (progn
      (if (/= lke (entlast))
(progn
;(alert "I was triggered")
  (foreach p Savedprops
    (SetDynProp (entlast) (car p) (cadr p))
  )
  (setq lke (entlast))
)
      )
      (killReactor nil nil)
    )
  )
)

(defun killReactor (callReact cmdArgs)
  (vlr-remove-all :vlr-Command-Reactor)
  (if insEnd:cmdreactor
    (progn (vlr-remove insEnd:cmdreactor)
   (setq insEnd:cmdreactor nil)
    )
  )
  (if insCan:cmdreactor
    (progn (vlr-remove insCan:cmdreactor)
   (setq insCan:cmdreactor nil)
    )
  )
  (if insFail:cmdreactor
    (progn (vlr-remove insFail:cmdreactor)
   (setq insFail:cmdreactor nil)
    )
  )
  (prompt "\nReactors cleared.")
)
(defun SetDynProp (e propname newval / obj v vval sal tot i)
  (setq obj (if (= (type e) 'vla-object)
      e
      (vlax-ename->vla-object e)
    )
  )
  (if (= (vlax-get-property obj 'isdynamicblock) :vlax-true)
    (progn
      (setq v (vla-getdynamicblockproperties obj)
    vval (vlax-variant-value v)
    sal (vlax-safearray->list vval)
    tot (length sal)
    i 0
      )
      (while (< i tot)
(if (= (vlax-get-property (nth i sal) "PropertyName") propname)
  (progn
    (vlax-put-property (nth i sal) "Value" newval)
    (setq i tot)
  )
  (setq i (1+ i))
)
      )
    )
  )
)

[code tags and formatting added :kdub]
Title: Re: Help Desperately Needed
Post by: Kerry on July 01, 2010, 07:33:48 PM

This may help :
http://forums.augi.com/showthread.php?p=1081131#post1081131
Title: Re: Help Desperately Needed
Post by: Hangman on July 01, 2010, 07:46:35 PM
First off, welcome to the swamp.
Secondly, when you are posting code, there's an icon that looks like the # symbol.  This is for code.  The way you have it currently posted makes it hard to read.
Thirdly, when creating a new post, try and make the title more appropriate to the topic of the code.

Anyway, don't mind me, I'm just passing along what was told me over and over again.


So, how much do you know about LiSP ??

< ... >
;;; **** Replace function in VLX for compatability with 2010+
(defun ZF_GET-ACADCOLOR ()
(VL-LOAD-COM)
(setq ZF_ACADCOLOR
(vla-GetInterfaceObject
(ZF_GET-ACAD-OBJECT)
(strcat "AutoCAD.AcCmColor."
(itoa (ATOI (GETVAR "ACADVER")))
)
)
)
)
 < ... >

The item listed in red in the quote is telling us that the program is searching for the ACAD version.  I can't see where it is checking this version against the program though.  I would assume there's a piece of code somewhere that will check the version against something and if the current ACAD version does not match, it kicks it out or stops running.

I would also think whoever wrote it is trying to confuse the reader for some reason.  
Code: [Select]
([color=red]itoa (ATOI (GETVAR "ACADVER"[/color])))

itoa = Integer to string conversion
atoi = string to integer conversion

So this is being converted to integer and back to string in one line.

Perhaps I am wrong in this assumption and would appreciate others sounding off on my contribution here.


< edited >  You should also recognize the one who wrote the code regardless of their current affiliation.
Title: Re: Help Desperately Needed
Post by: Kerry on July 01, 2010, 07:52:17 PM

nlanum ,

Welcome to theSwamp.

Just a couple of points.

It would help if you were to :

Indicate where the error happens.
Provide ALL functions so that anyone choosing to test can do so.
Provide some sort of explaination as to what the routine function is ( ie what are your expectations)

Not everyone is prepared to just run unknown code, nor have the time to decipher code that is a little complicated.
Title: Re: Help Desperately Needed
Post by: Kerry on July 01, 2010, 07:57:59 PM


I don't think this is what you want to use.

Command: (GETVAR "ACADVER")
;;==>> "18.1s (LMS Tech)"

won't you just want the "18"

try something like  (read  (GETVAR "ACADVER"))
;;==>> "18"
Title: Re: Help Desperately Needed
Post by: nlanum on July 01, 2010, 08:07:48 PM
Thank you for the comments about the proper etiquette for posting here.
I do appreciate it.

I can't find the string that you just posted.

I don't think this is what you want to use.

Code: [Select]
I don't think this is what you want to use.

Command: (GETVAR "ACADVER")
;;==>> "18.1s (LMS Tech)"

won't you just want the "18"

try something like  (read  (GETVAR "ACADVER"))
;;==>> "18"


I am attaching all the files in hopes that someone can save my a##.
Title: Re: Help Desperately Needed
Post by: Kerry on July 01, 2010, 08:17:16 PM

actually, thinking aboit it these 2 are equivalent

(read  (GETVAR "ACADVER"))
(itoa (ATOI (GETVAR "ACADVER")))
Title: Re: Help Desperately Needed
Post by: Kerry on July 01, 2010, 08:19:46 PM
I'm not prepared to run a VLX fron an untrusted source  .. sorry


however the problem isn't with the assignment to ZF_ACADCOLOR
Code: [Select]

 (setq ZF_ACADCOLOR
(vla-GetInterfaceObject
  (vlax-get-acad-object)
  (strcat "AutoCAD.AcCmColor."
  (itoa (ATOI (GETVAR "ACADVER")))
  )
)
  )

Returns
;;==>> #<VLA-OBJECT IAcadAcCmColor 000000002ba9f840>

(vlax-dump-Object ZF_ACADCOLOR T)

; IAcadAcCmColor: AutoCAD AcCmColor Interface
; Property values:
;   Blue (RO) = 0
;   BookName (RO) = ""
;   ColorIndex = 256
;   ColorMethod = 192
;   ColorName (RO) = ""
;   EntityColor = -1073741824
;   Green (RO) = 0
;   Red (RO) = 0
; Methods supported:
;   Delete ()
;   SetColorBookColor (2)
;   SetNames (2)
;   SetRGB (3)
Title: Re: Help Desperately Needed
Post by: Hangman on July 02, 2010, 10:47:34 AM
I'm not prepared to run a VLX fron an untrusted source  .. sorry

however the problem isn't with the assignment to ZF_ACADCOLOR
Code: [Select]

 (setq ZF_ACADCOLOR
(vla-GetInterfaceObject
   (vlax-get-acad-object)
   (strcat "AutoCAD.AcCmColor."
   (itoa (ATOI (GETVAR "ACADVER")))
   )
)
  )
< ... >

I agree with you Kerry, the problem is not with ZF_ACADCOLOR.  But like you pointed out,

actually, thinking aboit it these 2 are equivalent

(read  (GETVAR "ACADVER"))
(itoa (ATOI (GETVAR "ACADVER")))

These are equivalent.  It is simply getting the version of autocad here.  But according to the dump you posted, it's not even showing a version number to test against.  And it's not showing a variable to hold it either.
Which tells me this is merely fluff to confuse someone trying to edit the code.  There is probably a legitimate test in the VLX, so unless there is a hacker willing to crack open the VLX to get to the code, what do you do now ??
Title: Re: Help Desperately Needed
Post by: Kerry on July 02, 2010, 10:50:40 AM
< .. >  what do you do now ??

go to bed .
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 11:56:25 AM
And it's not showing a variable to hold it either. Which tells me this is merely fluff to confuse someone trying to edit the code.
Not that this helps solve the riddle with the rest of the code, but thought I'd chime in on this one little part...It's not being set to a variable or even checked for anything. It is all a part of one line:
Code: [Select]
(setq ZF_ACADCOLOR
(vla-GetInterfaceObject
   (vlax-get-acad-object)
   (strcat "AutoCAD.AcCmColor."
   (itoa (ATOI (GETVAR "ACADVER")))
   )
)
  )

;;is the same as
(setq ZF_ACADCOLOR (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (itoa (ATOI (GETVAR "ACADVER"))))))
IOW, the version number is just being appended to "AutoCAD.AcCmColor.", which Kerry showed is working.
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 12:23:51 PM
Well, I went ahead and loaded the EDI menu after adding the unzipped path to my support files paths. It all works just fine, except the dwg's for the blocks in the toolbar were not included in the zip. All the one's I tested in the Ribbon appear to be just fine. I never get any version incompatibility error.
Title: Re: Help Desperately Needed
Post by: nlanum on July 02, 2010, 12:28:11 PM
Jeff-

Thank you for the efforts.
Did you run this in acad 2011?
Title: Re: Help Desperately Needed
Post by: Hangman on July 02, 2010, 12:39:25 PM
< ... >
;;is the same as
Code: [Select]
(setq ZF_ACADCOLOR (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (itoa (ATOI (GETVAR "ACADVER"))))))IOW, the version number is just being appended to "AutoCAD.AcCmColor.", which Kerry showed is working.

OK, now you have my increasing interest so I need to ask;
First, what IS the purpose (do you believe) of the line
Code: [Select]
(itoa (ATOI (GETVAR "ACADVER")))  As Kerry pointed out and to my understanding, its redundant.
Second, where is it being appended to ??  The closest point I can see would be the "EntityColor = -1073741824", but that's not making any sense to me.  Of course, APPEND simply takes two lists and combines them into one and when Kerry dumped the object, did it not read the 'acadver' ??  Or perhaps I should ask, How is this Appending these two items together working ??
Third, why would this be appended to the "AutoCAD.AcCmColor" ??

I know all this isn't going to help much, but I am curious, this is getting interesting.
Title: Re: Help Desperately Needed
Post by: nlanum on July 02, 2010, 12:43:36 PM
here are a couple more files that I found.

EDI.fas

I have no idea what it is but in the folder I found it there was mention to the EDI.vlx file.
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 01:16:55 PM
Jeff-

Thank you for the efforts.
Did you run this in acad 2011?
Yes, that screen shot was in 2011
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 01:23:16 PM
Second, where is it being appended to ??  The closest point I can see would be the "EntityColor = -1073741824", but that's not making any sense to me.  Of course, APPEND simply takes two lists and combines them into one and when Kerry dumped the object, did it not read the 'acadver' ??  Or perhaps I should ask, How is this Appending these two items together working ??
Third, why would this be appended to the "AutoCAD.AcCmColor" ??

I know all this isn't going to help much, but I am curious, this is getting interesting.
The (strcat) is appending the version to the string:  "AutoCAD.AcCmColor." so the line of code becomes
Code: [Select]
(vla-GetInterfaceObject (vlax-get-acad-object) "AutoCAD.AcCmColor.18")
when used in 2010 & 2011. This is the format required to get the AcCmColor object in 2010, 2011, and probably 2012. By using the (itoa(atoi)) it makes sure to get the proper integer. For 2007-2009 this was 17.....
Title: Re: Help Desperately Needed
Post by: nlanum on July 02, 2010, 01:27:36 PM
Jeff-

Thank you for the efforts.
Did you run this in acad 2011?
Yes, that screen shot was in 2011



now I am more confused than ever. I could not get any of those tools to work in 2011.
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 01:37:27 PM
here are a couple more files that I found.

EDI.fas

I have no idea what it is but in the folder I found it there was mention to the EDI.vlx file.
OK, the error you see is defined in the FAS file. The mnl file section that you included in the first post is supposed to override the definition. So it seems like the VLX or FAS files are being loaded again AFTER the MNL has loaded. Make sure your acaddoc.lsp does not have these included. Also your startup suite should not include them.
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 01:46:22 PM
More info.....
Code: [Select]
;;; **** Replace function in VLX for compatability with 2010+
(defun ZF_GET-ACADCOLOR ()
  (VL-LOAD-COM)
  (setq ZF_ACADCOLOR
(vla-GetInterfaceObject
   (ZF_GET-ACAD-OBJECT)
   (strcat "AutoCAD.AcCmColor."
   (itoa (ATOI (GETVAR "ACADVER")))
   )
)
  )
)

;;; This is the original in the FAS, which is not usable(to us) code but shows where it's defined
;;; the above is set to overwrite this, providing this is not loaded afterwards
(defun ZF_GET-ACADCOLOR ()
(cond ZF_ACADCOLOR (
(cond T (
normal cond
nil
(VL-LOAD-COM )
(cond (= (ATOI (GETVAR "ACADVER")) 16) (
(cond (= (ATOI (GETVAR "ACADVER")) 17) (
(cond T (
normal cond
nil
(setq *ZF_LASTERROR "Incompatible AutoCAD Version")
normal cond
(EXIT )
normal cond
"AutoCAD.AcCmColor.17"
(setq ZF_ACADCOLOR (vla-GetInterfaceObject (ZF_GET-ACAD-OBJECT ) "AutoCAD.AcCmColor.16"))
normal cond
Title: Re: Help Desperately Needed
Post by: Hangman on July 02, 2010, 01:56:25 PM
< ... >
The (strcat) is appending the version to the string:  "AutoCAD.AcCmColor." so the line of code becomes
Code: [Select]
(vla-GetInterfaceObject (vlax-get-acad-object) "AutoCAD.AcCmColor.18")
when used in 2010 & 2011. This is the format required to get the AcCmColor object in 2010, 2011, and probably 2012. By using the (itoa(atoi)) it makes sure to get the proper integer. For 2007-2009 this was 17.....

Most interesting.  I have not tried accessing the AcCmColor so I have never run into this.  Thank you Jeff for the explanation, it is most enlightening for me.
Title: Re: Help Desperately Needed
Post by: nlanum on July 02, 2010, 02:21:55 PM
ok. I think things are starting to become a little less fuzzy.

How can I get these to load in the proper order?
Title: Re: Help Desperately Needed
Post by: Jeff_M on July 02, 2010, 02:30:46 PM
ok. I think things are starting to become a little less fuzzy.

How can I get these to load in the proper order?
OK, the error you see is defined in the FAS file. The mnl file section that you included in the first post is supposed to override the definition. So it seems like the VLX or FAS files are being loaded again AFTER the MNL has loaded. Make sure your acaddoc.lsp does not have these included. Also your startup suite should not include them.
If neither of these is the problem then try removing the FAS file from the support folder...although if it was there in 2010 and it worked, then it shouldn't matter in 2011 either. After that, I'm just not sure, because as I said it worked here just by unzipping and adding the path to them to my support paths.