OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: velasquez on May 25, 2009, 04:31:09 PM

Title: vla-insertBlock with MODAL form.
Post by: velasquez on May 25, 2009, 04:31:09 PM
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)
Title: Re: vla-insertBlock with MODAL form.
Post by: Fred Tomke on May 25, 2009, 10:46:36 PM
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
Title: Re: vla-insertBlock with MODAL form.
Post by: velasquez on May 26, 2009, 04:15:34 AM
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.
Title: Re: vla-insertBlock with MODAL form.
Post by: Kerry on May 26, 2009, 05:46:57 AM
Hi, velasquez,
Have you had a look at the Selections.LSP and .ODCL in the samples folder.

Regards
Kerry
Title: Re: vla-insertBlock with MODAL form.
Post by: velasquez on May 26, 2009, 06:09:42 AM
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
Title: Re: vla-insertBlock with MODAL form.
Post by: Fred Tomke on May 26, 2009, 08:10:32 AM
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

Title: Re: vla-insertBlock with MODAL form.
Post by: velasquez on May 26, 2009, 09:36:38 AM
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