TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Giuseppe Beatrice on September 06, 2016, 06:22:21 AM

Title: Strange behavior with the insertion of a block.
Post by: Giuseppe Beatrice on September 06, 2016, 06:22:21 AM
I have a really strange problem.
If I want to insert a block definition without inserting the block in the drawing, I have to use the instruction:
(command <full name of the block> nil)
All goes perfectly, but if I use a slightly different type of instruction it's not so more:
- with (command-s <full name of the block> nil) I have an error ... (command-s) unknown
- with (vl-cmdf <full name of the block> nil) I have an error ... Application Error: Invalid type sent as input comand
Can anyone please explain why these strangeness happens?
Thanks in advance.
Title: Re: Strange behavior with the insertion of a block.
Post by: ChrisCarlson on September 06, 2016, 08:13:17 AM
A block name is not a command name. Why not just use insert or a variant thereof?
Title: Re: Strange behavior with the insertion of a block.
Post by: Lee Mac on September 06, 2016, 08:26:25 AM
Since vl-cmdf evaluates the validity of the arguments prior to submitting them to the command-line, this expression will error if supplied with invalid input.
Title: Re: Strange behavior with the insertion of a block.
Post by: Giuseppe Beatrice on September 06, 2016, 09:17:28 AM
I regret for the lack of clarity; of course the complete instruction was (command "_.-insert" <ful-name-block> nil).
Many thanks Lee, you have lighted up my ignorance; then, even command-s return an error for the same reason.
Is there another way but (command "_.-insert" <ful-name-block> nil) to insert a block without inserting an instance of it in the drawing?
Title: Re: Strange behavior with the insertion of a block.
Post by: ChrisCarlson on September 06, 2016, 10:15:42 AM
I would insert the block and delete the new instance

Code - Auto/Visual Lisp: [Select]
  1. (if
  2.         (vl-cmdf "._insert" blk "_S" 1.0 "_R" 0.0 "_non" "0,0,0")
  3.                 (vl-cmdf "_.erase" (ssget "L") "")
  4.                 (princ "Block Insertion Error")
  5. )
Title: Re: Strange behavior with the insertion of a block.
Post by: snownut2 on September 06, 2016, 12:31:00 PM
There's always this.

http://www.lee-mac.com/copyblockdefinition.html (http://www.lee-mac.com/copyblockdefinition.html)

From Lee Mac....
Title: Re: Strange behavior with the insertion of a block.
Post by: MP on September 06, 2016, 12:51:32 PM
This isn't quite the same thing but it's inevitable someone will want to copy a block def between docs (which can be ODBX docs) ...

Code: [Select]
(defun _CopyBlockDef ( sourcedoc blockname targetdoc / block )

    (and
        (null
            (vl-catch-all-error-p
                (setq block
                    (vl-catch-all-apply
                        (function
                            (lambda ( )
                                (vla-item
                                    (vla-get-blocks sourcedoc)
                                    blockname
                                )
                            )
                        )
                    )
                )
            )
        )

        (null
            (vl-catch-all-error-p
                (vl-catch-all-apply
                   '(lambda ( )
                        (vlax-invoke-method
                            sourceDoc
                           'CopyObjects
                            (vlax-safearray-fill
                                (vlax-make-safearray
                                    vlax-vbObject
                                   '(0 . 0)
                                )
                                (list block)
                            )
                            (vla-get-blocks targetdoc)
                        )
                    )
                )
            )
        )
    )
)

FWIW cheers.
Title: Re: Strange behavior with the insertion of a block.
Post by: Lee Mac on September 06, 2016, 04:11:25 PM
You may get some ideas from this old program: Import Block (http://lee-mac.com/copyblockfromdrawing.html).
Title: Re: Strange behavior with the insertion of a block.
Post by: kdub_nz on September 06, 2016, 07:17:03 PM
I'm bewildered.
Have you tried the built in ADCENTER ??

The DesignCenter was designed to replicate table data.

It doesn't handle UCS's, but I imagine there are several shared versions on the site.
added: here's one from 9 years ago https://www.theswamp.org/index.php?topic=16994.msg205851#msg205851

Title: Re: Strange behavior with the insertion of a block.
Post by: Giuseppe Beatrice on September 07, 2016, 06:25:55 AM
Your availability is huge and I can only thank you all.
I think theswamp is the best site to learn Lisp.  :yay!: