VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why is this sendcommand running asynchronously ?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Arnaud_Lesauvage
701 Views, 1 Reply

Why is this sendcommand running asynchronously ?

Hi all !

 

Autocad Map 3D 2009 here.

 

I have writtent a VBA procedure which uses the very unfamous "sendcommand".

 

I need to retrieve a hatch boundaries. In VBA, AcadHatch.GetLoopAt will return a null array for a non-associative hatch. So I need to retrieve the boundaries and make the hatch associative first. This is also impossible in VBA (AcadHatch.AssociativeHatch can only be set at creation time).

 

So I thought I'd just issue a sendcommand "_-hatchedit " to recreate the hatch boundaries and associate them to the hatch. (command "_-HATCHEDIT" (handent "<my handle>") "_B" "_P" "_Y") to be more precise.

 

BUT, to my surprise, the sendcommand runs asynchronously, even though there is no user input in the process.

The autocad help clearly states that "This method is generally synchronous. However, if the command sent with this method requires any user interaction (such as picking a point on the screen) then this method will continue as soon as the user input begins. The command will then continue to be processed asynchronously."

 

Here is the sample code (just create a non associative hatch in the drawing to test it) :

Sub test()
    Dim oAcadHacth      As AcadHatch
    Dim oSelSet         As AcadSelectionSet
    Dim gpCode(1)       As Integer
    Dim gpValue(1)      As Variant
    
    Set oSelSet = ThisDrawing.SelectionSets.Add("TEST")
    gpCode(0) = 0:      gpValue(0) = "HATCH"
    gpCode(1) = 71:     gpValue(1) = "0"
    oSelSet.Select acSelectionSetAll, , , gpCode, gpValue
    
    ThisDrawing.Utility.Prompt vbCrLf
    For Each oAcadHacth In oSelSet
        ThisDrawing.Utility.Prompt "Before : " & oAcadHacth.AssociativeHatch
        ThisDrawing.SendCommand "(command ""_-HATCHEDIT"" (handent """ & oAcadHacth.Handle & """) ""_B"" ""_P"" ""_Y"")& vbcr"
        Application.Update
        ThisDrawing.Utility.Prompt "After : " & oAcadHacth.AssociativeHatch
    Next oAcadHacth
    
    oSelSet.Delete
    Set oSelSet = Nothing
End Sub

 

 

This command does not require any user input, so why is it running asynchronously ?

Thanks a lot for your help !

1 REPLY 1
Message 2 of 2

Ok, self replying.
The problem was not in the macro itself, it runs fine and is synchronous.
The problem was in the way it was called. I used (vla-RunMacro (vlax-get-acad-object) "Test"), and this runs in lisp synchronously so no other lisp command can run until the VBA macro called is finished (that's the way I understand it anyway).
Calling it simple with -VBARUN "Test" works just fine !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost