Author Topic: vla-insertBlock - Multi-line attribute in block ends up in outer space  (Read 1958 times)

0 Members and 1 Guest are viewing this topic.

Rustabout

  • Newt
  • Posts: 135
I'm writing a code that inserts a block. I'm finally getting rid of a lot of my ugly command line programming and using vla-insert for this kick at the can.

When I insert my block, the multi-line attribute f's off into outer space or disappears completely (still appears in drawings properties though). I thought there was something up with the (simple) block I made but using the insert command either at the command line or within LISP works just fine.

Anyone know off hand what might be causing this? I've otherwise had no issues with the VLA-INSERTBLOCK function.

NOTE: DO NOT PUT TIME AND EFFORT INTO SOLVING THIS UNLESS THE SOLUTION BENEFITS YOU AS WELL. I've started to work around this and I'm going to try entmake instead and then convert to a VLA_OBJECT thereafter. I'm just asking in case someone's run across the same problem and already knows the answer.

If anyones curious I'm going to try and make a live label ala Revit. For reference here's the line of code that's giving me trouble. You can probably create a block to test this quicker than downloading a block (I've tried this with multiple blocks):

(vla-insertBlock modelSpace (vlax-3d-point pt1) "BLOCK NAME" 1.0 1.0 1.0 blockAngle)

Rustabout

  • Newt
  • Posts: 135
Re: vla-insertBlock - Multi-line attribute in block ends up in outer space
« Reply #1 on: December 20, 2020, 06:50:57 PM »
entmake is even worse :-O .

What I might do is simply make the 'label' an entity which does not need to be modified. Either by making it MTEXT or a block with single line attributes. The mutlline attribute would have been nice in case users needed to 'squeeze' the label to fit something.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-insertBlock - Multi-line attribute in block ends up in outer space
« Reply #2 on: December 21, 2020, 02:19:03 PM »
Are you adding text to the attributereference?
This works for me:
Code - Auto/Visual Lisp: [Select]
  1. (setq pt1 (getpoint))
  2. (setq blk (vla-insertBlock modelSpace (vlax-3d-point pt1) "TEST" 1.0 1.0 1.0 0))
  3. (setq att (car (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))))
  4. (vla-put-textstring att "Just a test.\nSecond line.")

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: vla-insertBlock - Multi-line attribute in block ends up in outer space
« Reply #3 on: December 21, 2020, 03:50:30 PM »
entmake is even worse :-O .

But we already got this wheel.  :wink:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Rustabout

  • Newt
  • Posts: 135
Re: vla-insertBlock - Multi-line attribute in block ends up in outer space
« Reply #4 on: December 21, 2020, 09:16:32 PM »
Hi Jeff. The attribute is preset. Well for now it's preset. Maybe I'll try what you said as I only had it preset while testing out the block.

Since posting I've decided to go with a simpler MTEXT object and just add XDATA to it (I'm still decided my exact approach). Grrr1337: The link will be invaluable as 1) I need to brush up on my entmake'ing skills and 2) I'm (for now) adding my XDATA using Vanilla LISP. Juggling the objects from a LISP entity to a VLA-OBJECT might get me into hot water later on in the coding process. Also, it explains why (I originally forgot to mentioned this) using the ATTSYNC command on my block fixes the misplaced attribute.

I think what is happening is that my version of AutoCAD has some sort of a glitch, or the glitch only occurs if the multiline attribute is preset (single line attributes are appearing properly).

Off topic: In Jeff's code, line 4: the VLAX-INVOKE function actually bypasses some of the digging (skips the need to deal with the variant and safearray) and actually shoots out a list of VLA objects directly. The VLA-INVOKE-METHOD command produces the variant. I'm not sure why this is as Autodesk's help states that VLAX-INVOKE is legacy and was replaced by VLAX-INVOKE-METHOD but they obviously do different things. I had been using vlax-invoke because I noticed it in so many people's codes. Only when I decided I really needed to learn what I was doing did I start playing around with each version (I was struggling to get a coordinate list into a polyline I think and not understanding that it needed to be a variant [or a variant within a safearray?]).

Much thanks for your help guys!