vla-insertBlock with MODAL form.

Started by velasquez, May 25, 2009, 04:31:09 PM

Previous topic - Next topic

velasquez

I close the MODAL form. 
I ask for an insert point for a block. 
I indicate a point in the screen. 
The form is shown again. 
The block appears in the screen. 
The form should appear after the block. 
Am I making some wrong thing?

Code (autolisp) Select

(vla-insertBlock (JoyGetActiveSpace) ;_Pega o espaco ativo
(vlax-3d-point JoyInsPt)
"BlockName"
1 ;_xscalefactor
1 ;_ yscalefactor ent)
1 ;_ zscalefactor
0 ;_rotation)

Fred Tomke

Hi, velasquez, I don't know enough about your code but make sure that your form is showing within a loop.

Code (autolisp) Select

(defun c:MyProj_MyForm_pb_Cancel_OnClicked ()
  (dcl_form_close MyProj_MyForm 2)
); c:MyProj_MyForm_pb_Cancel_OnClicked

(defun c:MyProj_MyForm_pb_BlockInsert_OnClicked ()
  (dcl_form_close MyProj_MyForm 3)
); c:MyProj_MyForm_pb_BlockInsert_OnClicked

(setq doCont T)
(while doCont
  (setq doCont nil)
  (setq intForm (dcl_form_show MyProj_MyForm))
  (cond
    ((= intForm 2) (setq doCont nil)) ;; Cancelling the form via ESC or c:MyProj_MyForm_pb_Cancel_OnClicked
    ((= intForm 3)
     (if (and (setq JoyInsPt (vl-catch-all-apply 'getpoint (list "\nPick a point to insert block: ")))
              (not (vl-catch-all-error-p JoyInsPt)))
       (setq oBlock (vla-insertBlock (JoyGetActiveSpace) ;_Pega o espaco ativo 
                (vlax-3d-point JoyInsPt) 
                "BlockName" 
                1 ;_xscalefactor 
                1 ;_ yscalefactor ent
                1 ;_ zscalefactor 
                0 ;_rotation
            ))
     ))
  ); cond
); while


Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

velasquez

Hi Fred, 
My form this working within the loop. 
Your work seems better. 
Don't I want to take your time but do you have an example working? 
Does it can me to show? 
Thank you very much.

Kerry

Hi, velasquez,
Have you had a look at the Selections.LSP and .ODCL in the samples folder.

Regards
Kerry
Perfection is not optional.
My other home is TheSwamp

velasquez

I posted my complete code. 
I need to insert the block and to show the form again. 
This should happen after the insert of the block and not before. 
I don't know what am doing wrong.

Regards
Velasquez

Fred Tomke

#5
Sorry, was my mistake, I've forgotten the line (setq doCont T) after inserting the block.
Please forgive me!

I've removed some comments to highlight the new comments

Code (autolisp) Select

(defun c:Blki (/ intform oBlock strFileName strBlockName)
  (dcl_Project_Load "MyProj")

  (defun c:MyProj_MyForm_pb_Cancel_OnClicked ()
    (dcl_form_close MyProj_MyForm 2)
  ); c:MyProj_MyForm_pb_Cancel_OnClicked
 
  (defun c:MyProj_MyForm_pb_BlockInsert_OnClicked ()
    (dcl_form_close MyProj_MyForm 3)
  ); c:MyProj_MyForm_pb_BlockInsert_OnClicked

  (setq doCont T)
  (setq strBlockName "BOLA") ;; whatever was selected
  (while doCont
    (setq doCont nil)
    (setq intForm (dcl_form_show MyProj_MyForm))
    (cond
      ((= intForm 2) (setq doCont nil)) ; Cancelling
      ((= intForm 3) ; Selecting
       (if (and (or (tblsearch "Block" strBlockName)
                    (setq strFileName (findfile (strcat strBlockName ".dwg"))))
                (setq JoyInsPt (vl-catch-all-apply 'getpoint (list "\nPick a point to insert block: ")))
                (not (vl-catch-all-error-p JoyInsPt))
                (setq oBlock (vl-catch-all-apply 'vla-insertBlock
                                 (list (JoyGetActiveSpace) (vlax-3d-point JoyInsPt)
                                       (if (tblsearch "Block" strBlockName) strBlockName strFileName)
                                       1 1 1 0)))
                (not (vl-catch-all-error-p oBlock)))

           (vla-update (vlax-get-acad-object)) ;; otherwise you only see the new block after finishing the program

       ); if
       (setq doCont T)) ; I've forgotten this line

    ); cond
  ); while
); Blki


Fred

Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

velasquez

Hi Fred, 
I remembered after (setq doCont T). 
But I didn't work with (vla-update (vlax-get-acad-object)). 
Therefore I didn't see the block. 
Your code worked very well now. 

Thank you very much.
Vleasquez