Author Topic: error! need help!  (Read 2232 times)

0 Members and 1 Guest are viewing this topic.

flyfox1047

  • Guest
error! need help!
« on: March 12, 2014, 10:51:45 AM »
Why have error ?
Code: [Select]
>Select the curve
 ..>>Select the arrangement of objects along:
 ...>>>The length of the curve15.821,Enter the spacing: 5
 ....>>>>The spacing of first object & Curve endpoint<0.410>:
._copy
Select objects:   1 found
Select objects:
Specify base point or [Displacement/Multiple] <Displacement>: non Specify
second point or <use first point as displacement>: non
Command: _.rotate
Current positive angle in UCS:  ANGDIR=counterclockwise  ANGBASE=0
Select objects:   1 found
Select objects:
Specify base point: non
Specify rotation angle or [Copy/Reference] <0>:
Backtrace:
[0.48] (VL-BT)
[1.44] (*ERROR* "bad argument type: numberp: nil")
[2.39] (_call-err-hook #<SUBR @0e81e8c0 *ERROR*> "bad argument type: numberp:
nil")
[3.33] (sys-error "bad argument type: numberp: nil")
:ERROR-BREAK.28 nil
[4.25] (- 0.938951 nil)
[5.19] (C:SM)
[6.15] (#<SUBR @0e81e9d8 -rts_top->)
[7.12] (#<SUBR @0dcc435c veval-str-body> "(C:SM)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
Command:
 Error!

This is the source code:
Code: [Select]
(defun C:SM (/ A AN AN0 BASEPT BETWEEN BOOL CURVEBLOCK CURVELENGTH DISTANC EN FIRSTPOINT LASTB LASTBLIST LASTBLOCK N PP PT PT0 SSADD1 STRIN TRIN VT)


  (defun *error* (msg)
    (vl-bt)
    (if *DOC*
      (_EndUndo *DOC*)
    )
    (while (not (equal (getvar "cmdnames") "")) (command nil))
    (princ "\n Error!")
    (princ)
  )

  (defun stratpointT (en pt0 / CURVELENGTH L1)
    (setq CurveLength
   (vlax-curve-getDistAtParam
     en
     (vlax-curve-getEndParam en)
   )
    )
    (setq L1 (vlax-curve-getDistAtPoint en pt0))
    (< L1 (- CurveLength L1))
  )

  (defun NAME_BLK (CurveLength / A Y)
    (setq A (rtos (* (getvar "CDATE") 1E8)))
    (setq Y (/ CurveLength 5.0))
    (entmake (list '(0 . "LINE")
   (cons 10 (list 0 0 0))
   (cons 11 (list 0 y 0))
     )
    )
    (command "_.BLOCK"
     A
     "non"
     (list 0 (/ y 2.0) 0)
     (entlast)
     ""
    )
    A
  )

  (defun MyAttAdd (en n / ELIST N1 N3 NEND QIANZ STREND TEXT)
    (setq elist (entget (entnext en)))
    (setq text (cdr (assoc 1 elist)))
    (setq n3 (strlen text))  
    (setq strEND (getNumberS text))
    (setq Nend (nth (1- (length strEND)) strEND))
    (setq n1 (strlen Nend))  
    (setq qianZ (substr text 1 (- n3 n1)))  
    (setq strEND (+ (atof (car strEND)) n))  
    (setq strEND (strcat qianZ (rtos strEND 2 3)))
    (entmod (subst (cons 1 strEND) (assoc 1 elist) elist))
    (entupd en)
   
  )

  (defun MyTextAdd (en n / ELIST N1 N3 NEND QIANZ STREND TEXT)
    (setq elist (entget en))
    (setq text (cdr (assoc 1 elist)))
    (setq n3 (strlen text))
    (setq strEND (getNumberS text))  
    (setq Nend (nth (1- (length strEND)) strEND))
    (setq n1 (strlen Nend))  
    (setq qianZ (substr text 1 (- n3 n1)))  
    (setq strEND (+ (atof (car strEND)) n))  
    (setq strEND (strcat qianZ (rtos strEND 2 3)))
    (entmod (subst (cons 1 strEND) (assoc 1 elist) elist))
  )
 
  (vl-load-com)
  (or *DOC*
      (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (_StartUndo *DOC*)
  (setvar "nomutt" 1)
  (princ "\n >Select the curve")
  (while (not
   (and (setq en (ssget ":E:S" '((0 . "*LINE,ARC,ELLIPSE"))))
(setq en (ssname en 0))
   )
)
    (princ "\n >Re select the curve")
  )
  (setvar "nomutt" 0)
  (setq pt0 (vlax-curve-getClosestPointTo en (cadr (grread T 8))))
 
  (setq CurveLength
(vlax-curve-getDistAtParam
   en
   (vlax-curve-getEndParam en)
)
  )

  (setq curveBlock
(car (ENTSEL "\n ..>>Select the arrangement of objects along:"))
  )
  (if curveBlock
    nil
    (progn (setq A (NAME_BLK CurveLength))
   (command "_.INSERT" A "@" "" "" "")
   (setq lastblock (entlast))
   (setq curveBlock lastblock)
    )
  )
  (setq an0 (entget curveBlock))  
  (setq basePt (cdr (assoc 10 an0)))
  (setq an0 (cdr (assoc 50 an0)))  
 
  (setq bool T)
  (setq strin (strcat "\n ...>>>The length of the curve"
      (rtos CurveLength 2 3)
      ",Enter the spacing: "
      )
  )
  (while bool
    (initget 7)
    (setq between (getreal strin))
    (if (> between CurveLength)
      (progn (setq bool T) (alert "Object spacing must be smaller than the curve length!!!"))
      (setq bool nil)
    )
  )
  (initget 4)
  (setq strin (rtos (/ (rem CurveLength between) 2.0) 2 3))
  (setq
    distanc (getreal
      (strcat "\n ....>>>>The spacing of first object & Curve endpoint<" strin ">:")
    )
  )
  (if distanc
    nil
    (setq distanc (/ (rem CurveLength between) 2.0))
  )
 
  (setq n (fix (/ (- CurveLength distanc) between)))
  (if (stratpointT en pt0)
    (setq firstPoint distanc)
    (setq firstPoint (rem (- CurveLength distanc) between))
  )
  (setq ssadd1 (ssadd))

  (repeat (setq n (1+ n))
    (setq pt (vlax-curve-getPointAtDist en firstPoint)
  pp (vlax-curve-getParamAtPoint en Pt)  
  vt (vlax-curve-getFirstDeriv en pp)
  an (angle '(0 0 0) vt)
    )
    (command "._copy" curveBlock "" "non" basePt "non" PT)
    (setq LastB (entlast))
    (setq LastBList (entget LastB))

    (cond ((assoc 66 LastBList) (MyAttAdd LastB (setq n (1- n))))
  ((equal (cdr (assoc 0 LastBList)) "TEXT")
   (MyTextAdd LastB (setq n (1- n)))
  )
    )

    ;;(entmod (subst (cons 50 an) (assoc 50 LastBList) LastBList))
    (command "_.rotate" LastB "" "non" pt (/ (* 180 (- an an0)) pi))
    (setq ssadd1 (ssadd LastB ssadd1))
    (setq firstPoint (+ firstPoint between))
  )
  (if lastblock
    (command "._erase" lastblock "")
    (progn (initget "R  ")
   (setq trin
  (getstring "\nTo block rotated 180 degrees, input R<Enter>")
   )
   (if (or (equal trin "R") (equal trin "r"))
     (repeat (setq n (sslength ssadd1))
       (setq LastB (ssname ssadd1 (setq n (1- n))))
       (setq LastBList (entget LastB))
       (setq an (cdr (assoc 50 LastBList)))
       (setq an (+ an pi))
       (entmod (subst (cons 50 an) (assoc 50 LastBList) LastBList))
     )
   )
    )
  )
  (_EndUndo *DOC*)
  (princ)
)



(defun _StartUndo (*DOC*)
  (_EndUndo *DOC*)
  (vla-StartUndoMark *DOC*)
)

(defun _EndUndo (*DOC*)
  (if (= 8 (logand 8 (getvar 'UNDOCTL)))
    (vla-EndUndoMark *DOC*)
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: error! need help!
« Reply #1 on: March 12, 2014, 01:11:04 PM »
I did not get an error.

Is your error repeatable or random?

Perhaps a sample DWG file with your curve & block in it would help us help you.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

PKENEWELL

  • Bull Frog
  • Posts: 321
Re: error! need help!
« Reply #2 on: March 12, 2014, 05:14:44 PM »
At first glance: Based on the error backtrace not tracing any subfunctions, the problem probably lies on one of these lines of code:

Code - Auto/Visual Lisp: [Select]
  1.   (setq n (fix (/ (- CurveLength distanc) between))) ; Either Here
  2.   (if (stratpointT en pt0)
  3.     (setq firstPoint distanc)
  4.     (setq firstPoint (rem (- CurveLength distanc) between)) ; Or Here
  5.   )
  6. ...
  7. (command "_.rotate" LastB "" "non" pt (/ (* 180 (- an an0)) pi)) ; Or here
  8.  

I agree with CAB: If you want a better analysis, please provide a DWG with the block and curve.

EDIT: I have tested your code, with an open polyline, closed polyline, self-intersecting polyline, fit-curved polyline, a line, an Arc, an Ellipse, and a spline - both with your default block and my own block and I have not found any errors so far. It may have something to do with the curve you are trying to use it with? I don't know.
« Last Edit: March 12, 2014, 06:14:23 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

NICK_VNV

  • Newt
  • Posts: 64
Re: error! need help!
« Reply #3 on: March 13, 2014, 05:23:06 AM »
It seems problem is here
Code: [Select]
(setq
    distanc (getreal
      (strcat "\n ....>>>>The spacing of first object & Curve endpoint<" strin ">:")
    )
  )
based on your log you have just pressed ENTER on "....>>>>The spacing of first object & Curve endpoint<0.410>:"
so "distanc" is still nil and you get an error "bad argument type: numberp: nil"

NICK_VNV

  • Newt
  • Posts: 64
Re: error! need help!
« Reply #4 on: March 13, 2014, 05:28:08 AM »
And following code
Code: [Select]
(if distanc
    nil
    (setq distanc (/ (rem CurveLength between) 2.0))
  )
should be
Code: [Select]
(if (= distanc
    nil)
    (setq distanc (/ (rem CurveLength between) 2.0))
  )

flyfox1047

  • Guest
Re: error! need help!
« Reply #5 on: March 13, 2014, 07:35:59 AM »
Thank you all!
I'm sorry for the mistake.I thought that support all the objects. As a result, only support block object

PKENEWELL

  • Bull Frog
  • Posts: 321
Re: error! need help!
« Reply #6 on: March 13, 2014, 12:35:46 PM »
Good Catch NICK_VNV! I didn't see that. My eyes were making assumptions  :ugly:
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

flyfox1047

  • Guest
Re: error! need help!
« Reply #7 on: March 15, 2014, 04:41:42 AM »
If need support all the objects, not only block, Can modify it ?