AutoLISP not working

AutoLISP not working

vinju
Explorer Explorer
405 Views
5 Replies
Message 1 of 6

AutoLISP not working

vinju
Explorer
Explorer

Hi everyone, 

 

I've got problems with this script of mine... Still have to learn a lot.

 

So basically I want to write a AutoLISP that does the following:

 

- Let the user select a viewport

- retrieve the scale factor of that viewport by using PSVPSCALE

- then it should let the user select a dynamic block

- change one parameter of that dyn. block called "Abrufen2" (which is a lookup parameter) based on these correlations:


Import property - viewport scale variable
1.0 - 50
2.0 - 25
3.0 - 20
4.0 - 15
5.0 - 10
6.0 - 5
7.0 - 2.5
8.0 - 2
9.0 - 1.5
10.0 - 1.25
11.0 - 1
12.0 - 0.5
13.0 - 0.25
14.0 - 0.2
15.0 - 0.15
16.0 - 0.1
17.0 - 0.05
18.0 - 0.025
19.0 - 0.02
20.0 - 0.01

 

So if the scale factor is 0.5, I'd like it to change the import property to 12.0

 

The import properties are already in the lookup action table.

 

Here's the code so far:

 

(defun c:automassstab()
  (vl-load-com)
  (setq vp (getvar "PSVPSCALE"))
  (setq vpname (entsel "Select viewport: "))
  (if vpname
    (progn
      (setq vpname (cadr vpname))
      (setq bname (entsel "Select the dynamic block: "))
      (if bname
        (progn
          (setq bname (cadr bname))
          (setq props (entget bname))
          (setq scale_lookup_table '((50 . 1.0) (25 . 2.0) (20 . 3.0) (15 . 4.0) (10 . 5.0) (5 . 6.0) (2.5 . 7.0) (2 . 8.0) (1.5 . 9.0) (1.25 . 10.0) (1 . 11.0) (0.5 . 12.0) (0.25 . 13.0) (0.2 . 14.0) (0.15 . 15.0) (0.1 . 16.0) (0.05 . 17.0) (0.025 . 18.0) (0.02 . 19.0) (0.01 . 20.0)))
          (setq scale (vl-position vp (mapcar 'car scale_lookup_table)))
          (if (assoc "Abrufen2" props)
            (entmod (subst (cons "Abrufen2" (cdr (nth scale scale_lookup_table))) (assoc "Abrufen2" props) props))
            (princ "Selected block does not have the necessary parameter called 'Abrufen2'.")
          )
        )
      )
    )
  )
)

 

But I get the Error:

 

Incorrect argument type: lentityp (607.639 25.2777 0.0)

 

Maybe some of you all can help me with this. - Thanks 

0 Likes
406 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Remove d from cadr here

(setq bname (cadr bname))

 

0 Likes
Message 3 of 6

paullimapa
Mentor
Mentor

why are you using cadr when you should be using car?

(setq vpname (car vpname))

(setq bname (car bname))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 6

vinju
Explorer
Explorer

Thank you, I removed it and the error message is gone, but now it gives me the error message I made it say when it does not find the lookup parameter. - Problem is that the dyn. block I'm  selecting has the "Abrufen2" parameter. (I double and triple checked this by now) 

So I'm not sure what to do about this.

 

Still: Thank you for taking your time and if you have any other ideas on how I could fix this, please let me know 🙂

 

0 Likes
Message 5 of 6

vinju
Explorer
Explorer

Thank you, I applied this but now I am facing another problem, as you can see in my other response in this thread.

 

Thank you also for helping me 🙂

0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

You didn't learn anything from the previous thread, did you?

Here is one more piece of advice for you - function (dumpallproperties (car (entsel))) might come in handy.

 

btw hopefully you do understand why removing d fixed the issue.

 

0 Likes