Author Topic: need a quick piece of code ...  (Read 6623 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
need a quick piece of code ...
« on: April 23, 2010, 05:31:46 PM »
I have a selection set:
Code: [Select]
(setq lines (ssget "C" ac bc '((0 . "line"))))
(setq selLine (ssname Lines 0))
(Setq ss (ssget "L"))
And I want to drop a block on the midpoint of the line in the selection set.
How can I get the midpoint of the line in the selection set ??
For testing purposes, I've tried:
Code: [Select]
(command ".line" "_mid of" ss)
Quote
.line Specify first point: _mid of
Invalid point.
; error: Function cancelled
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: need a quick piece of code ...
« Reply #1 on: April 23, 2010, 05:46:40 PM »

Hint :

What is ss. "

What is selLine. "

What are you trying to find the "_MID" of ?

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #2 on: April 23, 2010, 05:49:54 PM »
Code: [Select]
(defun _Mid (e)
  ((lambda (eLst)
     (mapcar
       (function (lambda (a b) (/ (+ a b) 2.)))
       (cdr (assoc 10 eLst))
       (cdr (assoc 11 eLst))
     )
   )
    (entget e)
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #3 on: April 23, 2010, 05:59:56 PM »
Sorry, I was a little hasty on posting an answer. :|
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Hangman

  • Swamp Rat
  • Posts: 566
Re: need a quick piece of code ...
« Reply #4 on: April 23, 2010, 06:16:45 PM »
Sorry, I was a little hasty on posting an answer. :|

Actually Alan, that's what I was in need of, Thanks.
I wasn't sure if selecting the midpoint of a line was easier than what you posted,  ... I didn't want to calculate out the midpoint from the end and beginning as you have shown if I didn't have too.  but alas, I guess I do have to.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #5 on: April 23, 2010, 06:21:35 PM »
Sorry, I was a little hasty on posting an answer. :|

Actually Alan, that's what I was in need of, Thanks.
I wasn't sure if selecting the midpoint of a line was easier than what you posted,  ... I didn't want to calculate out the midpoint from the end and beginning as you have shown if I didn't have too.  but alas, I guess I do have to.
Yeah, but Kerry is right. I should have been helping, not giving you the answer.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: need a quick piece of code ...
« Reply #6 on: April 23, 2010, 06:30:15 PM »
< .... >
Yeah, but Kerry is right. I should have been helping, not giving you the answer.

No problem Alan.
I've just about accepted that the expectation of instant gratification is killing the learning process.  :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #7 on: April 23, 2010, 06:47:36 PM »
< .... >
Yeah, but Kerry is right. I should have been helping, not giving you the answer.

No problem Alan.
I've just about accepted that the expectation of instant gratification is killing the learning process.  :-)
You're absolutely correct. I should have made suggestions instead of just giving the code. I know you guys were good enough to teach me when I first got here.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: need a quick piece of code ...
« Reply #8 on: April 24, 2010, 01:07:27 PM »
< .... >
Yeah, but Kerry is right. I should have been helping, not giving you the answer.

No problem Alan.
I've just about accepted that the expectation of instant gratification is killing the learning process.  :-)

And obviously the "proper use of a subject line" process as well (no one will ever have this problem and they certainly wont need to search for it in the future either).  :-)

Edit:
Oh boy, looks like im in a rare mood today. *lmao*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #9 on: April 24, 2010, 07:47:20 PM »
< .... >
Yeah, but Kerry is right. I should have been helping, not giving you the answer.

No problem Alan.
I've just about accepted that the expectation of instant gratification is killing the learning process.  :-)

And obviously the "proper use of a subject line" process as well (no one will ever have this problem and they certainly wont need to search for it in the future either).  :-)

Edit:
Oh boy, looks like im in a rare mood today. *lmao*
LoL
Isn't that how we kicked off our forum-friendship?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #10 on: April 24, 2010, 08:16:14 PM »
Since I already spilled the beans, here's an example that's a bit more versatile...

Code: [Select]
(defun footos (e)
  (if e
    (vlax-curve-GetPointAtDist
      e
      (/ (vlax-curve-GetDistAtParam
           e
           (vlax-curve-GetEndParam e)
         )
         2.
      )
    )
  )
)

eg.
Code: [Select]
(command "_.line" (footos (car (entsel))))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: need a quick piece of code ...
« Reply #11 on: April 25, 2010, 03:11:33 AM »
Code: [Select]
(command "_.line" "_mid" (cadr (entsel)))
Speaking English as a French Frog

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a quick piece of code ...
« Reply #12 on: April 25, 2010, 08:21:17 AM »
Code: [Select]
(command "_.line" "_mid" (cadr (entsel)))
So you would feed it a point instead of ename. Interesting.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: need a quick piece of code ...
« Reply #13 on: April 25, 2010, 01:46:29 PM »
> LoL
> Isn't that how we kicked off our forum-friendship?

:smile: yes, I believe it was.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: need a quick piece of code ...
« Reply #14 on: April 27, 2010, 01:32:23 PM »
< .... >
Yeah, but Kerry is right. I should have been helping, not giving you the answer.

No problem Alan.
I've just about accepted that the expectation of instant gratification is killing the learning process.  :-)
You're absolutely correct. I should have made suggestions instead of just giving the code. I know you guys were good enough to teach me when I first got here.

Well guys, first off, I have a mindset to learn more by example.  So the code Alan threw out was hasty, but I have learned from it.  You see, when one doesn't know what to look for, it's pretty difficult to learn from hints:
Quote
Hint :
What is ss. "
What is selLine. "
What are you trying to find the "_MID" of ?

Although in this case, I already knew what it was I was looking for, I just didn't know in what format it was to happen.
Quote
I have a selection set:
...
And I want to drop a block on the midpoint of the line in the selection set.
How can I get the midpoint of the line in the selection set ??

So, I did learn from Alan's code, but I didn't use it.  I'm acually still learning how Lambda & mapcar works.
Here's what I ended up doing:
Code: [Select]
(setq selLine (ssname Lines 0)                            ; get first line in selection
            LineBeginPT (cdr (reverse (cdr (reverse (assoc 10 (entget selLine))))))
            LineEndPT (cdr (reverse (cdr (reverse (assoc 11 (entget selLine))))))
            LineBeginX (car LineBeginPT)
            LineBeginY (car (cdr LineBeginPT))
            LineEndX (car LineEndPT)
            LineEndY (car (cdr LineEndPT))
            LineMidX (/ (+ LineBeginX LineEndX) 2.0)
            LineMidY (/ (+ LineBeginY LineEndY) 2.0)
            LineMidPT (append LineMidPT (list LineMidX) (list LineMidY) (list Z))
      )

A lengthy way to go about it, but it's what I know at the moment.  It was this: (lambda (a b) (/ (+ a b) 2.))) that sparked my memory.

Now I have seen this before, but I couldn't remember how it was formatted:
Code: [Select]
(command "_.line" "_mid" (cadr (entsel)))This is actually what I was looking for, or more precisely, this:  (cadr (entsel)))

So I Thank you guys, for you interest in helping me learn by asking questions, for your hastiness in just throwing out code, and for your concern in how things are learned.  To me you guys are like gods, the masters of LiSP and I do respect your thoughts and comments.  I do want you to know I am not trying to brown nose and I'm just looking for someone to write code for me.  I enjoy writing it and learning it.

With that said, what are you Se7en, referring to when you mentioned:
Quote
...
And obviously the "proper use of a subject line" process as well (no one will ever have this problem and they certainly wont need to search for it in the future either).

Please advise if I have not followed protocol or have haphazardly posted my subject line inproperly.  I would really like to know what the proper procedure is.

I have read that when writing code, it is a good practice to put comments at then end of a line of code or just after the line of code to remind yourself or someone else who may be editing the code, what your intentions were at the time the code was written and what the code is doing.  I am trying to put that into practice, and am learning that many practices I have may be unorthodox and haphazardly done.  So I appreciate these comments and would like to know what your intentions and understanding is in posting the comment.

Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~