Author Topic: InsertBlock using Vlisp  (Read 9315 times)

0 Members and 1 Guest are viewing this topic.

sparky

  • Guest
InsertBlock using Vlisp
« on: June 24, 2004, 11:29:51 AM »
RetVal = object.InsertBlock(InsertionPoint, Name, Xscale, Yscale, ZScale, Rotation)

InsertionPoint = Variant (three-element array of doubles)
Name = String

I'm trying this....

(vl-load-com)
  (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
  (setq mspace (vla-get-modelspace acadDocument))
  (setq BotLeft '(601.0 725.0))
  (setq Insert_Pt (vlax-3D-point BotLeft))
  (setq File_Name (getstring T "\nPlease enter the Block name to insert (with file extension .dwg)\n"))
  (setq FileAndDir (strcat "C:\\" File_Name))
  (setq Title_Insert (vla-InsertBlock mspace Insert_Pt FileAndDir))

But it doesn't work...please... don't giggle!

Can anyone help.  It's been bugging me.  

 :?

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #1 on: June 24, 2004, 11:36:08 AM »
Add the scale and rotation like so;
Code: [Select]

 (setq Title_Insert
(vla-InsertBlock mspace Insert_Pt FileAndDir 1.0 1.0 1.0 0.0)
)
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
It's still buggin' me...
« Reply #2 on: June 24, 2004, 11:57:45 AM »
tried that but still doen't work...actually think I tried that before as VB says that if the last 4 arguments aren't passed then the defaults kick in.

Any other suggestions...

The error message I get is..

; Fehler: Automatisierungsfehler. Keine Beschreibung verfügbar.

which is German for ;error: Automation failure. No description available.

 :wink:  :?

SMadsen

  • Guest
InsertBlock using Vlisp
« Reply #3 on: June 24, 2004, 12:06:38 PM »
As Mark points out, you need to pass all arguments in lisp when using the VLA functions.
I tried your code with the replacement that Mark suggested and it works fine.

sparky

  • Guest
Still doesn't work...
« Reply #4 on: June 25, 2004, 04:59:13 AM »
Sorry, got distracted by the football yesterday evening...

No joy on this side.  Tried both with and without the scale & Rotation params but still can't see the block on my modelspace screen!  Should I see it?  Or is it hidden somewhere in the software background.  I couldn't open the original drawing last night after trying the code out.  It seemed to be inuse by another program....somewhere in cyberspace??

Tried regen but still didn't make an appearance!!

Any suggestions... have I a bug in my LISP IDE?

Thanks for the prompt replies yesterday.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #5 on: June 25, 2004, 08:42:30 AM »
I'm not sure by looking at the code you posted what the problem is but give this code a try.
Code: [Select]

(defun ins-meblock (/ get-mspace ins_pt blk me_block)
  (vl-load-com)

  (defun get-mspace ()
    (vla-get-modelspace
      (vla-get-activedocument
        (vlax-get-acad-object)
        )
      )
    )

  (if (setq ins_pt (getpoint "\nSelect insertion point: "))
    (if (setq blk (getfiled "Select Block to insert" "" "dwg" 8))
      (setq me_block
            (vla-insertblock
              (get-mspace)
              (vlax-3d-point ins_pt)
              blk
              1.0
              1.0
              1.0
              0.0
              )
            )
      )
    )
  (if (not (vlax-object-released-p me_block))
    (vlax-release-object me_block)
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
the InsertBLock "bug"
« Reply #6 on: June 25, 2004, 09:03:57 AM »
Tried your function...works a breeze...I'm a little ashamed at my ineloquent way of expressing MYself in comparison to you...anyhow enough flattery...

A colleague tried my code and it worked on his machine.  Something must have been seriously wrong with the earlier part of my coding session yesterday.  Had a look at a few pages on unexpected  ActiveX behaviour and it may have something to do with "implicit object creation" as opposed (of course) to "explicit calls to object creation".  

However, I shall try to emulate your style and structure as it is much easier to read and well...it works!

Thanks a bunch...at least I Know the mspace object ain't broke, but'll have to check the block object...I think it got a batterring yesterday!

It's amazing how many things I don't know...(getfiled - nice one)!

sparky

  • Guest
Small change....
« Reply #7 on: June 25, 2004, 09:27:30 AM »
Using your code, but replaced the getfiled function with a simple string of path and filename. . .Automation error; No description available!

I'd like to use a dialog box to selęct a Drawing Size, Scale and Format then just insert the appropriate Block, based on a naming system for the blocks (Scale info not included). So the user will generate the blockname themselves and therefore I need to just have the block inserted without a dialog for File selection.

Tell me to quit this if I'm re-inventing the wheel...it is however just an exercise with a vew to learning how to manipulate AutoCAD.

The ActiveX refernece states that unexpected behaviour will occur when the Name argument is uninitialised.  What does that mean exactly?

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #8 on: June 25, 2004, 09:37:27 AM »
Alright, let's look at the block name first. Is the path to the blocks included in the acad search path? Does the block name indicate the the path to the block? i.e. if the user enters "foo" then the path to that block is 'c:\\blocks\\foobars\\" so in your program you would do;
Code: [Select]

(strcat "c:\\blocks\\foobar\\" blkname)

does that make sense?
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
No! (foo stuff makes no sense)
« Reply #9 on: June 25, 2004, 09:54:34 AM »
Quote from: Mark Thomas
Alright, let's look at the block name first. Is the path to the blocks included in the acad search path? Does the block name indicate the the path to the block? i.e. if the user enters "foo" then the path to that block is 'c:\\blocks\\foobars\\" so in your program you would do;
Code: [Select]

(strcat "c:\\blocks\\foobar\\" blkname)

does that make sense?


I don't mean to irritate you...The path to the blocks is not included in the Acad search paths. I'll add it in and see waht happens...guess I'd just name the block then and let the getfiled do a library search(?). as for strcat, that is what I was using before and it didn't work.

sparky

  • Guest
THanks (bowing ceremoniously)...THanks (bowing ceremoniously
« Reply #10 on: June 25, 2004, 10:03:06 AM »
Added it to the Acad Support path and it goes in no problem without using getfiled.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #11 on: June 25, 2004, 10:05:10 AM »
>I don't mean to irritate you...
you're not.

hang on a minute, i need to whip up some code to explain.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #12 on: June 25, 2004, 10:18:43 AM »
Ok take a look at this. assumes path to blocks is in the acad search path.
Code: [Select]

(defun ins-meblock (/ get-mspace ins_pt blk_name me_block)
  (vl-load-com)

  (defun get-mspace ()
    (vla-get-modelspace
      (vla-get-activedocument
        (vlax-get-acad-object)
        )
      )
    )

  (if (setq ins_pt (getpoint "\nSelect insertion point: "))
    (if (setq blk_name (getstring T "\nEnter Block name (without ext.): "))
      (if (findfile (strcat blk_name ".dwg"))
        (setq me_block
              (vla-insertblock
                (get-mspace)
                (vlax-3d-point ins_pt)
                blk_name
                1.0
                1.0
                1.0
                0.0
                )
              )
        )
      )
    )
  (if me_block
    (if (not (vlax-object-released-p me_block))
      (vlax-release-object me_block)
      )
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
Knowledge is Power
« Reply #13 on: June 25, 2004, 10:55:17 AM »
You're a Good man.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #14 on: June 25, 2004, 10:59:21 AM »
Quote
I'd like to use a dialog box to selęct a Drawing Size, Scale and Format

Could you expand on the above a little more?

drawing size means what, DIMSCALE ?

scale = ?

format = ?
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
Format =, Size=
« Reply #15 on: June 25, 2004, 11:33:24 AM »
Drawing Size = ISO A0-A4 , B1 (inserted into mspace, BL corner of a viewport, which has been trimmed of all crossing entities)

Format= simply Port. or Land.

Scale is standard 1:200 to 1:10000 (1 AutoCAD unit to 1m)

sparky

  • Guest
Got to go home...
« Reply #16 on: June 25, 2004, 11:37:11 AM »
Other responsibilities.

Thanks for the help...could pick up a thread over the WE but maybe not.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
InsertBlock using Vlisp
« Reply #17 on: June 25, 2004, 11:40:01 AM »
So you're inserting title blocks .........  I must have missed that some where along the line. Well before we create the dcl code let's do it on the command line first. Then once we get it working we can move into the dcl stuff, unless of course you have already done the dcl stuff. :D
TheSwamp.org  (serving the CAD community since 2003)

sparky

  • Guest
trying to run before the walk/strut/swagger
« Reply #18 on: June 28, 2004, 02:39:51 AM »
Want to get into vb and Vlisp, with only a few months experience of Lisp, and zip other programming experience....you can see the issues I am sure.  

I'll try to take some advice floating around this forum...browse the forums, but don't seek answers to all your problems here, otherwise you'll never learn who to solve them yourself!

SMadsen

  • Guest
Re: trying to run before the walk/strut/swagger
« Reply #19 on: June 28, 2004, 04:53:30 AM »
Quote from: sparky
I'll try to take some advice floating around this forum...browse the forums, but don't seek answers to all your problems here, otherwise you'll never learn who to solve them yourself!

A very good and always relevant point!