galibardi
galibardi

Reputation: 11

AutoLisp function won't work with valid args in a file but works in another

It's a function that takes 3 args (point list) and returns a vector. It works fine in other files but in not in the file I need (error "bad argument type: 2D/3D point: nil"). Points supplied to the function can be used well in a command function to draw a line which is OK. AutoCAD restarted.

Function:

(defun Bisect3p (Op, p1, p2 / V1 V2)
  (setq V1 (mapcar '- p1 Op)
    V2 (mapcar '- p2 Op)
  )  
  (GS:NORMALIZE (mapcar '+ (GS:NORMALIZE v1) (GS:NORMALIZE v2)))
)

and

(defun GS:Normalize (v)
  ((lambda (l)
     (if (/= 0 l)
       (mapcar (function (lambda (x) (/ x l))) v)
     )
   )
    (distance '(0 0 0) v)
  )
)

Data that works in one fie but not another even when points are acquired manually with GETPOINT but works like this:

(BISECT3P 
'(-0.575892 -1.27646 2.82506) 
'(-0.219971 -1.45442 2.69577) 
'(-0.219971 -1.05649 2.82506) 
) 

not like this:

(Bisect3p ed_start ed_end a_start)

where args hold the same values I would like to understand what is this.

Upvotes: 0

Views: 61

Answers (3)

dexus
dexus

Reputation: 53

Lisp doesn't use comma's between the variables. Just spaces:

(defun Bisect3p (Op, p1, p2 / V1 V2)

Should be:

(defun Bisect3p (Op p1 p2 / V1 V2)

Ps. For getting a unit vector (gs:normalize) you can also use this function I wrote:

(defun Mat:unit (v)
  ;; Unit Vector - dexus
  ;; Args: v - vector
  (trans '(0 0 1) v 0 t)
)

Upvotes: 0

Pablo Gaitan
Pablo Gaitan

Reputation: 18

Try changing the OSNAPCOORD variable from the default value of 2 to 1.

I suppose the object snap is set differently in each file.

Upvotes: 0

CAD Developer
CAD Developer

Reputation: 1697

Maybe You have the same variable names in calling function and other function, so it overrides Your values one step before to nil. So Your functions get nils. To check that You can (print Op) and other input variables or run in debug mode to check which variable and where get nil passed.

Upvotes: 0

Related Questions