Author Topic: Automation Error  (Read 1699 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Automation Error
« on: July 28, 2015, 09:33:05 AM »
This is alittle strange. I have the following code that works on most setups. I have another setup that when I run the code it says the following:

Code: [Select]
Command: X2ML
Select Objects: 1 found
Select Objects: 1 found, 2 total
Select Objects: 1 found, 3 total
Select Objects: 1 found, 4 total
Select Objects Unknown command "X2ML". Press F1 for Help.
; error; Automation Error. Description was not provided.
Command:





Here is the code trying to get to work:

Code: [Select]
(defun c:X2ML (/ _dxf lp lp2 lpe ml ss txt x)
  (defun _dxf (code ename)
    (if ename
      (cdr (assoc code (entget ename)))
    )
  )          -->
  (cond ((null (and (setq ss (ssget ":L" (list '(0 . "text,line,solid"))))
    (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
       )
)
(print "Bye...")
)
((not (setq
lp (_dxf 12 (setq lpe (car (vl-remove-if-not '(lambda (x) (= "SOLID" (_dxf 0 x))) ss))))
      )
)
(print "Leader point not found...")
)
((not (setq lp2
     (car (vl-sort (apply 'append
  (mapcar '(lambda (x) (list (_dxf 10 x) (_dxf 11 x)))
  (vl-remove-if-not '(lambda (x) (= "LINE" (_dxf 0 x))) ss)
  )
   )
   '(lambda (a b) (> (distance a lp) (distance b lp)))
  )
     )
      )
)
(print "Lines not selected...")
)
((not (setq txt (vl-sort (vl-remove-if-not '(lambda (x) (= "TEXT" (_dxf 0 x))) ss)
'(lambda (a b) (> (cadr (_dxf 10 a)) (cadr (_dxf 10 b))))
)
      )
)
(print "Text not selected...")
)
(t
(command "._mleader" lp lp2 "")
(setq ml (vlax-ename->vla-object (entlast)))
(vla-put-textstring
   ml
   (vl-string-right-trim
     "\\P"
     (apply 'strcat (mapcar '(lambda (x) (strcat (_dxf 1 x) "\\P")) txt))
   )
)
(vla-put-layer ml (_dxf 8 (car txt)))
(vla-put-textstylename ml (_dxf 7 (car txt)))
(vla-put-textheight ml (_dxf 40 (car txt)))
(vla-put-arrowheadsize ml (distance lp (_dxf 10 lpe)))
(mapcar 'entdel ss)
)
  )
  (princ)
)


Thanks for the help guys
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Automation Error
« Reply #1 on: July 28, 2015, 09:59:11 AM »
Just a shot in the dark but maybe your current mleaderstyle (getvar 'cmleaderstyle) content type is set to something other than 2 (Mtext). So when the routine tries to set the text of the leader it $h!+s the bed :)
Quote
;   TextAttachmentDirection = 0
;   TextBackgroundFill = Exception occurred
;   TextBottomAttachmentType = 0
;   TextDirection = Exception occurred
;   TextFrameDisplay = 0
;   TextHeight = 0.125
;   TextJustify = Exception occurred
;   TextLeftAttachmentType = 1
;   TextLineSpacingDistance = Exception occurred
;   TextLineSpacingFactor = Exception occurred
;   TextLineSpacingStyle = Exception occurred
;   TextRightAttachmentType = 1
;   TextRotation = Exception occurred
;   TextString = Exception occurred
;   TextStyleName = Exception occurred
;   TextTopAttachmentType = 0
;   TextWidth = Exception occurred

Try adding this check and see if it fixes your problem:
Code - Auto/Visual Lisp: [Select]
  1. (defun _contentypetext-p (stylename / e)
  2.   (and (setq e (cdr (assoc -1 (dictsearch (namedobjdict) "acad_mleaderstyle"))))
  3.        (setq e (cdr (assoc -1 (dictsearch e stylename))))
  4.        (= 2 (vla-get-contenttype (vlax-ename->vla-object e)))
  5.   )
  6. )
  7. (_contentypetext-p (getvar 'cmleaderstyle))
« Last Edit: July 28, 2015, 10:09:50 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Automation Error
« Reply #2 on: July 28, 2015, 10:13:47 AM »
Ding... You win! Thanks a bunch!
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Automation Error
« Reply #3 on: July 28, 2015, 10:31:25 AM »
Ding... You win! Thanks a bunch!
:)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC