Thanks a lot for your help! It certainly was crucial to kickstart my
script. Specially since I didn't know I could send Lisp commands with
SendCommand().

Here's what I'm doing:


Em Seg, 2009-01-05 às 10:15 +0000, Kelie escreveu:
> Ronan,
> 
> Thanks for taking time to explain what you're after. Here is an ugly way of
> achieving what you're trying to do. If you know AutoLisp/VisualLisp, this 
> would
> be quite easy to follow. I'm not aware that there is a COM/ActiveX function
> equivalent to the ssgetfirst function. HTH.
> 
I'm not using ssgetfirst, since that would require the user to already
have the correct object selected before invoking the script. I'm using
doc.Utility.GetEntity(), which prompts the user to select an object. The
only problem with it is that the command box keeps displaying "Command:"
between my calls (and those are not SendCommand calls).
A related problem is that with doc.Utility.GetDistance() the prompt is
the second argument and I don't know how to pass the first argument as
it's optional and unwanted in my case.
> import comtypes.client
> app = comtypes.client.GetActiveObject("AutoCAD.Application")
> doc = app.ActiveDocument
> 
> #This assumes user has picked/selected ONE object to measure
> cmd1 = '(setq enamePicked (ssname (cadr (ssgetfirst)) 0)) '
> doc.SendCommand(cmd1)
> 
> #Start the MEASURE command. Add the rest of the command as you wish.
The thing is that when I use GetEntity() I obtain a Python COM object,
not something I can use with a lisp command, so now I'm converting from
one to the other with a function which calls doc.SendCommand('(setq %s
(handent "%s")) ' % (name_string, python_objec.Handle) )
> cmd2 = '(command "MEASURE" enamePicked) '
and use cmd = '(command "MEASURE" name_string "block" "block_name" "Y" %
f) ' % dist_from_GetDistance
> doc.SendCommand(cmd2)
> 
> #clean the variable after done with the MEASUREMENT command
> cmd3 = '(setq enamePicked nil) '
> doc.SendCommand(cmd3)

So, is there an easier way to convert variables from python to lisp,
without using SendCommand() ?

Also, I'm had some problems with type coercion. In the VB examples, the
variable types are declared before using, which coerce return types. The
comtypes documentation is terrible and I didn't find anything to do
similar. The problem is that ms.Item(number), where ms is the
ModelSpace, returns an IAcadEntity object, but sometimes I need methods
from the main class (or pointer), like IACadBlockReference. Since I
didn't find how to do it, I dug deep and found a way to do it like this:
item=comtypes.POINTER(comtypes.gen.AutoCAD.IAcadBlockReference).from_param(ms.Item(number))
That seems a bit long, just to use the Explode() function, which is
available for IACadBlockReference objects but not IACadEntity ones.
Is there a more direct way to do it?

By the way, I wonder why we must enter array.array('d', coords) when a
function requires an array of doubles, but when something should output
an array of doubles, comtypes gives a tuple.

Thanks a lot,
Ronan


------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to