Author Topic: Get Block  (Read 21553 times)

0 Members and 2 Guests are viewing this topic.

nivuahc

  • Guest
Re: Get Block
« Reply #45 on: March 16, 2006, 01:15:41 PM »
Code: [Select]
User picks block to export
The block maintains the name
Export the block to new location
Maintain insert point

I would start there and build on it. That's just me. Too much information tends to overwhelm. YMMV.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Get Block
« Reply #46 on: March 16, 2006, 01:19:15 PM »
You guys are moving faster than I I can figure things out.

Samething is always happening to me, Joker. I just try to read and put to use what the nice folks around here put forward. If we seem a bit short, we're working at the same time. Just relax and take it at your own pace, ask questions, keep a positive attitude, and take most comments with a grain of salt.  :roll:

Enjoy theSwamp!!!
I drink beer and I know things....

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #47 on: March 16, 2006, 01:28:14 PM »
You guys are moving faster than I I can figure things out.
To start with, don't look at the code posted.  Start with replys 18, and 19 (or earlier) and go from there.  Ask as many questions are you need to, to understand what you are doing.  That way you will learn, instead of just copying code.
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get Block
« Reply #48 on: March 16, 2006, 01:44:32 PM »
I have removed all my posts from this thread.
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.

nivuahc

  • Guest
Re: Get Block
« Reply #49 on: March 16, 2006, 01:53:35 PM »
I have removed all my posts from this thread.

Why?

Even if they don't help joker, surely they have merit and could possibly help someone else

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #50 on: March 16, 2006, 11:11:06 PM »
Ok, I stared this earlier but the thread took off faster than I could write this
so I held off posting. This is my feeble attempt at explaining how this lisp could
be written. Note that there are many ways to code so I am attempting to take a very
basic approach to this routine. This is what I have so far & lack time to finish so
please someone step in & complete the routine & expiation and correct any mistakes
I have made. Also fill in any gaps I left. <please excuse the spelling & grammar too> :)

joker you will need do create a function you can call from the command line.
It may look like this
Code: [Select]
(defun c:ReBlock()
; your code goes here
)
Note that for every opening parentheses there must be a closing parenthesis.
See the help file for explanation of a defun
You can call ReBlock from the command line, It won't do anything yet but you will fix that.
Also note that the semicolon starts a comment
From the Help File:
Code: [Select]
; Single-Semicolon Starts at the comment-column position, as defined by the
                           "Single-Semicolon comment indentation" format option.
;; Current-Column         The comment appears starting on a new line, indented at the 
                          same level as the last line of program code.
;;; Heading or 0-Column Appears on a new line, without indentation.

So this is what I often do, wrap the pseudo code with the function as Tim did earlier.
He picked ReBlock as the function name but you can pick your own name. Obviously it
should be meaningful to you.
Code: [Select]
(defun c:ReBlock()
  ;User picks block to export
  ;Insert the block at 0,0
  ;Explode the block
  ;Collect the new entities in a list
  ;Change all the entities to color of layer if color ByLayer
  ;Change all the entities to layer zero
  ;wblock out the explode pieces, ? any user input ?
  ;Delete the explode pieces
)
Now you start adding code to preform the tasks described. Note that the pseudo code may
change as you develop your routine & discover things you did not consider in the beginning.
That's just part of the process, for me that is.

Lets add the code that tim provided to explode & collect. He will explain it later.
Let me say that there are some error prevention & recovery code that you will want but
to keep it simple at first just stick to the basic pseudo code requirements first.

Code: [Select]
(defun c:ReBlock()
  ;User picks block to export
  ;Insert the block at 0,0
  ;Explode the block and Collect the new entities in a list
  (setq EntList
             (mapcar 'vlax-vla-object->ename
                     (vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
              )
  )
  ;Change all the entities to color of layer if color ByLayer
  ;Change all the entities to layer zero
  ;wblock out the explode pieces, ? any user input ?
  ;Delete the explode pieces
)

OK, how about the first item, picking the block to work with.
Do you see how that may be accomplished?

Looking at Tim's full version we can barrow this:
Code: [Select]
(setq ss (ssget ":E:S" '((0 . "INSERT"))))That's different in that I added ":E:S" which limits the selection to one object.
This code gives control to the user to select object(s) & adds there Entity Name to a 'selection set'
This selection set is stored in the variable named ss. In our case here it will only contain one
item. In Tim's code it can contain many items. (setq ss (ssget '((0 . "INSERT"))))
The '((0 . "INSERT")) is a filter making sure that only INSERT's can be selected. That is the label
given to blocks that exist in model or paperspace.
So here is the updated code:

Code: [Select]
(defun c:ReBlock()
  ;User picks block to export
  (setq ss (ssget ":E:S" '((0 . "INSERT"))))
  ;Insert the block at 0,0
  ;Explode the block and Collect the new entities in a list
  (setq EntList
             (mapcar 'vlax-vla-object->ename
                     (vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
              )
  )
  ;Change all the entities to color of layer if color ByLayer
  ;Change all the entities to layer zero
  ;wblock out the explode pieces, ? any user input ?
  ;Delete the explode pieces
)

Now we need the "Entity Name" of that insert. We get that with this:
Code: [Select]
(setq ename (ssname ss 0))So ename is the variable now holding the item entity name the user selected.
To get the block name we look at DXF code 2 like this:
Code: [Select]
(setq blkname (cdr (assoc 2 (entget ename))))WE can use it to insert a copy of that block by using the INSERT command.
Code: [Select]
(command "_.INSERT" blkname '(0.0 0.0 0.0) 1 1 1 0)
Here is the code so far.
Code: [Select]
(defun c:ReBlock()
  ;User picks block to export
  (setq ss (ssget ":E:S" '((0 . "INSERT"))))
  ;Get the block name from the entity list
  (setq ename (ssname ss 0))
  (setq blkname (cdr (assoc 2 (entget ename))))
  ;Insert the block at 0,0 and save its ename in variable ent
  (command "_.INSERT" blkname '(0.0 0.0 0.0) 1 1 1 0)
  (setq ent (entlast))
  ;Explode the block and Collect the new entities in a list
  (setq EntList
             (mapcar 'vlax-vla-object->ename
                     (vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
              )
  )
  ;Change all the entities to color of layer if color ByLayer
  ;Change all the entities to layer zero
  ;wblock out the explode pieces, ? any user input ?
  ;Delete the explode pieces
)
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.

Jim Yadon

  • Guest
Re: Get Block
« Reply #51 on: March 16, 2006, 11:44:39 PM »
You guys are moving faster than I I can figure things out.

I know how you feel. Sometimes I feel like the family dog on National Lampoon's Vacation. It's really great when the guys get going. It's just unfortunate that they forget sometimes that they've got us tied to the bumper with our lack of knowledge. LISP is not one of my strong points.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get Block
« Reply #52 on: March 16, 2006, 11:58:39 PM »
Joker,

Where are you from and what is your native language ?
How well do you understand English ?

Have you done any customisation of AutoCAD at all ? if so, what ?

.. knowing this will make people better able to assist you.

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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get Block
« Reply #53 on: March 17, 2006, 07:27:21 AM »
I have removed all my posts from this thread.



Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

M-dub

  • Guest
Re: Get Block
« Reply #54 on: March 17, 2006, 08:09:45 AM »
I have removed all my posts from this thread.





Took the words right out of my keyboard!

LE

  • Guest
Re: Get Block
« Reply #55 on: March 17, 2006, 10:48:40 AM »

Where are you from and what is your native language ?
How well do you understand English ?

Have you done any customisation of AutoCAD at all ? if so, what ?

.. knowing this will make people better able to assist you.


Can the above be part of a FAQ, as many times someone not having English as a native language [like me], might translated or interpreted words literally... Things like Jokes, double meaning words, or bad words for example [that are used here]... are hard to understand...

nivuahc

  • Guest
Re: Get Block
« Reply #56 on: March 17, 2006, 11:04:05 AM »
Can the above be part of a FAQ, as many times someone not having English as a native language [like me], might translated or interpreted words literally... Things like Jokes, double meaning words, or bad words for example [that are used here]... are hard to understand...

That's actually a pretty good suggestion, LE. A daunting task, to say the least, but good idea nonetheless.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #57 on: March 17, 2006, 11:57:56 AM »
Joker,

  Once you get as far as Alan (CAB) has shown, let us know, and we will show you have to finish the code.
Tim

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

Please think about donating if this post helped you.

Jim Yadon

  • Guest
Re: Get Block
« Reply #58 on: March 17, 2006, 09:35:05 PM »
... or bad words for example [that are used here]... are hard to understand...

Someone used foul language here? :?

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Get Block
« Reply #59 on: March 17, 2006, 09:59:44 PM »
Ducks, chickens, geese, quail....
     
I drink beer and I know things....