Author Topic: shortening a lisp quick question  (Read 3244 times)

0 Members and 1 Guest are viewing this topic.

diarmuid

  • Bull Frog
  • Posts: 417
shortening a lisp quick question
« on: February 18, 2011, 06:44:49 AM »

Hi Guys, quick question:

Is there a shorter way of writing this?

Code: [Select]
(if (or(tblsearch "block" "M-STagLin01")
        (tblsearch "block" "M-STagLin02")
        (tblsearch "block" "M-STagLin03")
        (tblsearch "block" "M-STagLin04"))
            (progn
            (Alert  (strcat "\nIncorrect Line-tag line in use in this P&ID. Please repair "
                           "\nthe drawing using the Button utility provided. Should you"
                    "\nrequire assisatance please contact tech-ops.")
            )
            )
 )
 
If you want to win something run the 100m, if you want to experience something run a marathon

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: shortening a lisp quick question
« Reply #1 on: February 18, 2011, 07:02:07 AM »
(and (vl-some '(lambda (a) (tblsearch "block" (strcat "M-STagLin0" a))) '("1" "2" "3" "4"))
     (Alert (strcat "\nIncorrect Line-tag line in use in this P&ID. Please repair "
                    "\nthe drawing using the Button utility provided. Should you"
                    "\nrequire assisatance please contact tech-ops."
            ) ;_  strcat
     ) ;_  Alert
)

Pepe

  • Newt
  • Posts: 87
Re: shortening a lisp quick question
« Reply #2 on: February 18, 2011, 07:04:52 AM »
Maybe this?

Code: [Select]
(if (vl-some '(lambda (x) (tblsearch "BLOCK" x)) '("M-STagLin01" "M-STagLin02" "M-STagLin03" "M-STagLin04"))
  (Alert "\nIncorrect Line-tag line in use in this P&ID. Please repair\nthe drawing using the Button utility provided. Should you\nrequire assisatance please contact tech-ops.")
  )

Slainte!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: shortening a lisp quick question
« Reply #3 on: February 18, 2011, 04:31:04 PM »
I would roll my own table search function where you could supply a list of names to search for, and either return after it finds one, or have it return an associate list, with the names found, and the block definition entity.

With each ' tblsearch ' call, you are stepping though all block definitions ( or all until the one is found ), and since you might call it multiple times, that is a slow way to do it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: shortening a lisp quick question
« Reply #4 on: February 18, 2011, 04:50:58 PM »
What about using tblobjname?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: shortening a lisp quick question
« Reply #5 on: February 18, 2011, 05:10:42 PM »
Calling (vla-Item...) on the Blocks collection might be an acceptable substitute (with the (vl-catch-all-apply...) wrappings of course).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Pepe

  • Newt
  • Posts: 87
Re: shortening a lisp quick question
« Reply #6 on: February 24, 2011, 05:15:47 AM »
Evgeny:

I didn't see your reply before I posted mine (same ways, but different).

Only a question about (just to improve myself): Why AND instead IF  :? ? (I suppose it's in order to avoid an ELSE, but it could have it's own logic...)

Thanks in advance.

diarmuid

  • Bull Frog
  • Posts: 417
Re: shortening a lisp quick question
« Reply #7 on: February 24, 2011, 05:24:05 AM »
Thanks for all of the input Guys

go raibh maith agat
If you want to win something run the 100m, if you want to experience something run a marathon

diarmuid

  • Bull Frog
  • Posts: 417
Re: shortening a lisp quick question
« Reply #8 on: February 24, 2011, 10:46:36 AM »
Thanks for the help,

The reason i was getting the help window appearing was my code showed:

(command "explode" "l" "")

This was incorrect, the extra "" at the end was not needed. (sure when you type out the command you need an extra "enter" to exit the comment, but from inside a lisp you dont when you select "last".

Regards

Diarmuid

If you want to win something run the 100m, if you want to experience something run a marathon

diarmuid

  • Bull Frog
  • Posts: 417
Re: shortening a lisp quick question
« Reply #9 on: February 24, 2011, 11:09:25 AM »
Sorry guys, wrong topic, ive posted it to the correct topic

 :lol:
If you want to win something run the 100m, if you want to experience something run a marathon

chlh_jd

  • Guest
Re: shortening a lisp quick question
« Reply #10 on: February 26, 2011, 11:36:43 AM »
just Readily
Code: [Select]
(if (vl-some '(lambda (x) (tblsearch "BLOCK" (strcat "M-STagLin0" x)))
     '("1" "2" "3" "4")
    )
  (Alert
    "\nIncorrect Line-tag line in use in this P&ID. Please repair\nthe drawing using the Button utility provided. Should you\nrequire assisatance please contact tech-ops."
  )
)
« Last Edit: February 26, 2011, 11:54:42 AM by chlh_jd »

chlh_jd

  • Guest
Re: shortening a lisp quick question
« Reply #11 on: February 26, 2011, 11:38:17 AM »
oh Evgeniy  & Pepe has Provided the shorten  :?
« Last Edit: February 26, 2011, 11:55:09 AM by chlh_jd »