Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Variant type object arrays
#1
Good day everyone,

I've been making some scripts with Autohotkey before and decided to move forwards and learn python(i know there is ironpython for making .NET scritps for autocad, but for now, id like to learn "basics").
Just started, few days ago, and wanted to make COM object to connect to autocad.
I managed to do everyting and connect to COM object with the help of "pyautocad" library.
where i'm stuck is in making selection set filter parameters, as its is not documented in pyautocad(maybe?).

So, in Autohotkey script looks like this(syntax is simmilar, shouldnt be problem as example):
So, i make 2 objects/variables : FilterType, FilterData.
FilterType := VarArrayCreate(VT_I2 := 2, "0", "8") # i send 3 variables to my function VarArrayCreate(below), with variables VT_I2 := 2 is same as just sending "2", but we can see datatype more clearly, not just digit. so, 2 stands for "16-bit signed int" in autohotkey, for more read here - autohotkey Object types. , next variable is "0" - autocad dxfCode, baiscly 0 is for autocad object types, like: lines, circle, polyline, etc..., last variable "8" - same, as 0, just for Layers.
FilterData := VarArrayCreate(VT_VARIANT := 0xC, "line", "LayerName") # Basicly same as above, just the type of 0xC is VARIANT.
So with FilterType i call funtion below. and create array object of "16-bit signed int", and with FilterData "VARIANT" type array.


VarArrayCreate(Type=0xC, Values*) #VarArrayCreate - this is function name, in python case, class ???
{
arr := ComObjArray(Type, Values.MaxIndex()) #this basicly creates ComObject with datatype that have sent parameters.
for i, v in Values{
arr[i-1] := v # -1 is needed becouse in autohotkey array starts with 1, and in autocad it should start from 0
}
return arr
}
So in General i need two arrays, one of 16bit integers, and other with variant type.
Looks kinda simple function, yet i cant figure out how to create such object array with specific type of data.
Any help appreciated,
And please make short example with core only, and not 300 lines codes, im new, i wont figure out such things(unless they work and all i need to send my variables :) )
To provoke on answer, one should ask, is Python inferior in object based arrays than AutoHotkey ? :D
Quote
#2
(Jul-28-2018, 05:37 PM)anbra Wrote: where i'm stuck is in making selection set filter parameters, as its is not documented in pyautocad(maybe?).
did you check http://pyautocad.readthedocs.io/en/latest/

what does selection set filter parameters mean?
(Jul-28-2018, 05:37 PM)anbra Wrote: And please make short example with core only, and not 300 lines codes, im new, i wont figure out such things(unless they work and all i need to send my variables :) )
To provoke on answer, one should ask, is Python inferior in object based arrays than AutoHotkey ? :D

This is not going to provoke answers... Show us your code so far and we can try to help from there...
Quote
#3
Code so far :
import pyautocad
import os
import comtypes
import time

from pyautocad import *
ACAD = Autocad(create_if_not_exists=True)
try:
    ACAD.ActiveDocument.SelectionSets.Item("SS2").Delete()
except:
    pass 
SS2obj = ACAD.ActiveDocument.SelectionSets.Add("SS2")
FilterType = "0" #it should be array of integers
FilterData = "Line" # this should be array of variants(strings)
SS2obj.Select("5","","", FilterType, FilterData) #[url=https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files/GUID-A809CD71-4655-44E2-B674-1FE200B9FE30-htm.html]Here[/url]link whats needed in autocad, cant link directly, go to selectionSet, Select(under Methods) #Also, noticed i cannot make empty commas. ",,," so i guess ,"","", should work ?
SS2obj.Highlight("1")
This how it looks in autohotkey wihtout comments:
SS2obj := ACAD.ActiveDocument.SelectionSets.Add("SS2")
FilterType := VarArrayCreate(2, "0", "8")		
FilterData := VarArrayCreate(0xC, "Line", "LayerName") 
SS2obj.Select("5",,, FilterType, FilterData)

VarArrayCreate(Type=0xC, Values*)
{
	arr := ComObjArray(Type, Values.MaxIndex())
	for i, v in Values{ 
		arr[i-1] := v
		; MsgBox % v "," i
	}
	return arr
}
This is the error Visual Studio shows, if this helps :
_ctypes.COMError: (-2147352567, 'Exception occurred.', ('Invalid argument FilterType in Select', 'AutoCAD', 'C:\Program Files\Autodesk\AutoCAD 2018\HELP\OLE_ERR.CHM', -2145320939, None))
Also, quick note. there is in pyautocad some arrays with types in the link you gave above, but there are no "variant" array, and integer of 32 bit is burried in library, for me as newb, a bit hard to "extract" into simple function.
This is the array given in pyautocad of integers
pyautocad.types.aInt(*seq)
Returns array.array of ints (‘l’ code) for passing to AutoCAD
buran wrote Jul-28-2018, 07:06 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#4
Just a bump, with some notes.
Can anyone at least lead me on the path, how to define variables ?
Is there any functions to make variables, 16-bit signed int, and/or, "variant" ?
something like this returns 32 bit integer ? :
MyVar = float(MyVar)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 139 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  Type hinting - return type based on parameter micseydel 2 151 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object of type set is not JSON serializable enigma619 5 1,559 Dec-19-2019, 03:30 PM
Last Post: enigma619
  type of object as a string Skaperen 1 210 Dec-02-2019, 08:01 AM
Last Post: midarq
  Object of type Scoreboard is not JSON serializable lsepolis123 9 3,363 Aug-13-2019, 11:22 AM
Last Post: lsepolis123
  Object and type class Uchikago 2 289 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  Object type of Node to json bhojendra 4 776 Apr-28-2019, 01:36 PM
Last Post: bhojendra
  TypeError: object of type 'NoneType' has no len() - what do it mean? leviathan54 4 3,024 Apr-20-2019, 12:04 PM
Last Post: leviathan54
  Getting error "Type error-a bytes-like object..." mrapple2020 1 2,334 Apr-06-2019, 06:37 PM
Last Post: mrapple2020
  Object of type 'Status' is not JSON serializable ndakena 1 1,984 May-28-2018, 06:35 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)