Author Topic: Error when run lisp on newfile  (Read 2347 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Error when run lisp on newfile
« on: March 22, 2015, 04:29:56 AM »
When run this lisp on a new file comes error
Put in Old file works great
Code: [Select]
Command: OPL
 click first corner
 click second corner; error: Automation Error. Key not found
I belive that it is beacuse of MakeLayer subroutine but do not know why.  :-(
Code - Auto/Visual Lisp: [Select]
  1. ;|------------ Opening Lines -------------------
  2.             q_|_|| _\|| q_|| _\|               
  3.                                                
  4.   To add rectangle and crossing lines to show  
  5.   opening                                      
  6. ------------------------------------------------
  7.   Author: Hasan M. Asous, 2013                 
  8.         ALL RIGHT RESERVED TO ALL              
  9.                                                
  10.   Contact: HasanCAD @ TheSwamp.org,            
  11.            asos2000 @ CADTutor.net             
  12.            HasanCAD@gmail.com                  
  13. ------------------------------------------------
  14.   Version: 1      2014 05 18                   
  15. ________________________________________________
  16.                                               |;
  17.  
  18.  
  19.         ;     q_|_|| _\|| q_|| _\|     ;
  20.         ;       Mainroutine Start      ;
  21.  
  22. (defun c:OpeningLines () (c:opl))
  23. (defun c:opl ( / clyr l o ortmd p1 p2 p3 p4 ) (vl-load-com)
  24.         spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc)))
  25.  
  26.   (mapcar '(lambda ( a b c d ) (MakeLayer a b "Continuous" c T 0 d))
  27.           '("S-OPEN" "S-OPEN-PATT" "S-SLAB-EDGE" "S-STRS-ELEV" "S-STRS-STEP" "S-STRS-IARO")
  28.           '(3 1 4 1 212 1)
  29.           '(0.3 0.09 0.4 0.15 0.3 0.25)
  30.           '("STRUCTURAL OPENING" "STRUCTURAL OPENING HATCH" "EDGE OF SLAB" "STAIR ELEVATION" "STAIR STEP" "INTERNAL STAIR ARROWS")
  31.           )
  32.  
  33.   (while
  34.     (if (and (setq p1 (getpoint "\n click first corner"))
  35.              (setq ortmd (getvar "orthomode"))
  36.              (setvar "orthomode" 0)
  37.              (setq p2 (getcorner p1 "\n click second corner"))
  38.              (setvar "orthomode" ortmd)
  39.              )
  40.       (progn
  41.         (setq p1 (trans p1 1 0 )
  42.               p2 (trans p2 1 0 )
  43.               p1X (min (nth 0 p1) (nth 0 p2))
  44.               p1Y (min (nth 1 p1) (nth 1 p2))
  45.               p2X (max (nth 0 p1) (nth 0 p2))
  46.               p2Y (max (nth 1 p1) (nth 1 p2))
  47.               )
  48.         (setq p1 (list p1X p1Y 0)
  49.               p2 (list p2X p2Y 0)
  50.               p3 (list p2X p1Y 0)
  51.               p4 (list p1X p2Y 0)
  52.               ptlist (list p1 p3 p2 p4)
  53.               ptlist (apply 'append ptlist)
  54.               )
  55.         (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1))))
  56.         (vlax-safearray-fill tmp ptlist)
  57.         (setq obj (vla-addPolyline spc tmp))
  58.         (vla-put-closed obj :vlax-true)
  59.         (vla-put-layer obj "S-OPEN")
  60.         (vla-put-color OBJ 256)
  61.         (makeline p1 p2 "Continuous" "S-OPEN-PATT")
  62.         (makeline p3 p4 "Continuous" "S-OPEN-PATT")
  63.         )
  64.       )))
  65.  
  66. (princ "\n      q_|_|| _\\|| q_|| _\\|")
  67. (princ "\n  Type  OPL  to invoke the lisp ")
  68.  
  69.         ;     q_|_|| _\|| q_|| _\|     ;
  70.         ;       Mainroutine End        ;
  71.  
  72.  
  73.         ;     q_|_|| _\|| q_|| _\|     ;
  74.         ;       Subroutine Start       ;
  75.  
  76. (defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
  77.     ;; (MakeLayer name colour linetype lineweight willplot bitflag description )
  78.     ;; Specifications:
  79.     ;; Description        Data Type        Remarks
  80.     ;; -----------------------------------------------------------------
  81.     ;; Layer Name          STRING          Only standard chars allowed                 
  82.     ;; Layer Colour        INTEGER         may be nil, -ve for Layer Off, Colour < 256 
  83.     ;; Layer Linetype      STRING          may be nil, If not loaded, CONTINUOUS.      
  84.     ;; Layer Lineweight    REAL            may be nil, 0 <= x <= 2.11                  
  85.     ;; Plot?               BOOLEAN         T = Plot Layer, nil otherwise               
  86.     ;; Bit Flag            INTEGER         0=None, 1=Frozen, 2=Frozen in VP, 4=Locked  
  87.     ;; Description         STRING          may be nil for no description               
  88.     ;; Function will return list detailing whether layer creation is successful.       
  89.     ;; © Lee Mac 2010
  90.  
  91.   (or (tblsearch "LAYER" name)
  92.     (entmake
  93.       (append
  94.         (list
  95.           (cons 0       "LAYER")
  96.           (cons 100     "AcDbSymbolTableRecord")
  97.           (cons 100     "AcDbLayerTableRecord")
  98.           (cons 2       name)
  99.           (cons 70      bitflag)
  100.           (cons 290     (if willplot 1 0))
  101.           (cons 6       (if (and linetype (tblsearch "LTYPE" linetype)) linetype "CONTINUOUS"))
  102.           (cons 62      (if (and colour (< 0 (abs colour) 256)) colour 7))
  103.           (cons 370     (fix (* 100 (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0))))
  104.           )
  105.         (if description (list (list -3 (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description)))))
  106.         ))))
  107.  
  108. (defun makeline (str end Ltp lyr )
  109.   (entmake (list (cons 0 "LINE")        ; ***
  110.                (cons 6 Ltp)             ; Linetype name (present if not BYLAYER)
  111.                (cons 8 lyr)             ; Layer
  112.                (cons 10 str)            ; Start Point
  113.                (cons 11 end)            ; End Point
  114.                (cons 39 0.0)            ; Thickness (optional) default = 0
  115.                (cons 62 256)            ; Color number (present if not BYLAYER);
  116.                (cons 210 (list 0.0 0.0 1.0)))))
  117.  
  118.         ;     q_|_|| _\|| q_|| _\|     ;
  119.         ;        Subroutine End        ;
  120.  
  121.  

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Error when run lisp on newfile
« Reply #1 on: March 22, 2015, 06:03:21 AM »
Try adding:

Code - Auto/Visual Lisp: [Select]
  1. (regapp "AcAecLayerStandard")

to the start of the MakeLayer function.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Error when run lisp on newfile
« Reply #2 on: March 22, 2015, 08:25:13 AM »
Try adding:

Code - Auto/Visual Lisp: [Select]
  1. (regapp "AcAecLayerStandard")

to the start of the MakeLayer function.

Working perfect
Thanks LEE

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Error when run lisp on newfile
« Reply #3 on: March 22, 2015, 08:44:30 AM »
But why is this?
Should I regapp all subroutine? to be aplicable for new files?

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Error when run lisp on newfile
« Reply #4 on: March 22, 2015, 08:51:56 AM »
Working perfect
Thanks LEE

Excellent, you're welcome  :-)

But why is this?
Should I regapp all subroutine? to be aplicable for new files?

No, the regapp is required in this case because the layer description is stored as xdata attached to the layer record under the AcAecLayerStandard application ID; this App ID may not be registered when the program is first used, hence causing the layer to fail to be created, resulting in the subsequent 'Automation Error. Key not found' error when the ActiveX Layer property is set to a layer which does not exist.

ChrisCarlson

  • Guest
Re: Error when run lisp on newfile
« Reply #5 on: March 23, 2015, 08:08:21 AM »
The Automation Key not found error is pretty vague (compared to other error codes which help pin-point the issue). How did you determine it was the layer function?

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Error when run lisp on newfile
« Reply #6 on: March 23, 2015, 08:26:31 AM »
The Automation Key not found error is pretty vague (compared to other error codes which help pin-point the issue). How did you determine it was the layer function?

It is the only call to an ActiveX property which sources the property value from a VL Collection (the 'key not found' error arises when attempting to access an item not present in a collection, e.g. using the ActiveX Item method).

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Error when run lisp on newfile
« Reply #7 on: March 23, 2015, 08:45:51 AM »
Try adding:

Code - Auto/Visual Lisp: [Select]
  1. (regapp "AcAecLayerStandard")

to the start of the MakeLayer function.
I belive that part of code should be added to layersubroutine.
Thats leads us to another enquairy.
Should we register all codes deal with xdata?

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Error when run lisp on newfile
« Reply #8 on: March 23, 2015, 09:47:04 AM »
Should we register all codes deal with xdata?

Before attaching xdata under a given Application ID, the Application ID must first be registered using regapp (or added to the ActiveX registeredapplications collection); you can test whether the App ID is registered using tblsearch on the APPID table, however, since supplying the regapp function with an already registered App ID has no effect, the tblsearch check may be considered unnecessary.