Jump to content

Get Handle to Objects in section Viewport


Recommended Posts

Hi
Does anybody know, how to get a handle related to the geometry of the vp cache "vs.GetVPGroup(h, 3) or the VP coordinates to the Object on the Design Layer?
Target would be tagging or annotate Elements in a Section viewport by script. Somehow it would work because the data-tag can also can access to this elements. 

I can imagine that it is necessary to evaluate the original object of a location from the vp coordinates and the section plane. Or is there an other solution for that?

DomC
 

Link to comment

The VP cache just literally contains the lines and polylines that make up the hidden line render. If you're annotating by the physical appearance in the VP (e.g. object heights), this could work, but you won't be able to access the drawing objects.

 

Data tags use some special code that's not available in VS or the SDK. My guess it that the attachment tool is using the VP view and visibility settings to query objects in the corresponding design layers.

Link to comment

Thanks for your worthwhile feedbacks. So far my strategy (But I do not know if it will work reliable enough)

1.  Inside the Section there is a Section Line Type 86 that contains the position of the section and a direction matrix
2. There are Informations on the Section VP directly that tells, if section is horizontal or vertical
3. The VP cache Group contains the projected geometry of the elements 
In combination of this 3 information it is possible to compare the Design-Layer coords and the section coords.

I build some functions to test what works. So far i see the following stumbling stocks:
- There are differences if the horizontal section was created from clip cube or from sectioning a VP
- VP cache has not the same informations if the objects behind section plane are disabled
- So far my function are not secure to return always the right informations


Prototype Method to get Section Line:
Gets Section Informations
 

 = vs.FSActLayer()
rname = 'Section Line2'

def create_field_value_dict(obj, rname):
	rhandle = vs.GetObject(rname)
	num_fields = vs.NumFields(vs.GetObject(rname))
	fdict = {'found' : True}
	for i in range(1, num_fields+1):
		fname = vs.GetFldName(rhandle, i)
		value = vs.GetRField(obj, rname, fname)
		fdict[fname] = value
		
	return fdict

def get_sl_in_vp(vp):
	obj = vs.GetVPGroup(vp, 2)
	#vs.Message(str(obj))
	groups = []
	while obj != vs.Handle(0):
		t = vs.GetTypeN(obj)
		if t == 11:
			groups.append(obj)

		obj = vs.NextObj(obj)
			
	section_line = vs.Handle(0)
	
	#vs.Message(str(groups))
	for group in groups:
		obj = vs.FInGroup(group)
		while obj != vs.Handle(0):
			t = vs.GetTypeN(obj)
			n = rname
			if t == 86 and n == 'Section Line2':
				section_line = obj
				
				
				break
			
			obj = vs.NextObj(obj)

	return section_line

section_line = get_sl_in_vp(h)
m = vs.GetEntityMatrix(section_line)
fdict = create_field_value_dict(section_line, rname)
fdict['entity_matrix'] = m
fdict['is_horizontal'] = vs.GetObjectVariableBoolean(h, 1048)

vs.Message(str(fdict))


Prototype Method to get VP cache infos:
This Function puts a 3D Locus on the Design-Layer in Projection to the Objects vertical to Section Plane.

h = vs.FSActLayer()
rname = 'Section Line2'
lh = vs.GetLayerByName('Konstruktionsebene-1')
fdict = {}

def create_field_value_dict(obj, rname):
	rhandle = vs.GetObject(rname)
	num_fields = vs.NumFields(vs.GetObject(rname))
	fdict = {'found' : True}
	for i in range(1, num_fields+1):
		fname = vs.GetFldName(rhandle, i)
		value = vs.GetRField(obj, rname, fname)
		fdict[fname] = value
		
	return fdict
	

def get_poly_in_vp(vp):
	obj = vs.GetVPGroup(vp, 3)
	
	groups = []
	while obj != vs.Handle(0):
		t = vs.GetTypeN(obj)
		if t == 11:
			groups.append(obj)

		obj = vs.NextObj(obj)
	
	#vs.AlrtDialog(str(groups))		
	objs = []
	for group in groups:
		obj = vs.FInGroup(group)
		while obj != vs.Handle(0):
			t = vs.GetTypeN(obj)
			#vs.AlrtDialog(str(t))
			if t in [5, 21]:
				if vs.GetFPat(obj) != 0:
					objs.append(obj)
				
			obj = vs.NextObj(obj)

	return objs


objs = get_poly_in_vp(h)
fdict['polys'] = objs
fdict['is_horizontal'] = vs.GetObjectVariableBoolean(h, 1048)

vs.AlrtDialog(str(fdict['is_horizontal']))
#vs.AlrtDialog(str(objs))

def get_center_points(objs):
	center_points_3D = []
	for obj in objs:
		p = vs.HCenter(obj)
		if fdict['is_horizontal']:
			m_pt = p[0], p[1], 0
			vs.AlrtDialog(str(m_pt))

			
		else: #vertical section y = z
			m_pt = p[0], 0, p[1]
			
			
		center_points_3D.append(m_pt)
			
	return center_points_3D

center_points_3D = get_center_points(objs)
			
for p in center_points_3D:			
	vs.Locus3D(p)
	locus = vs.LNewObj()
	#vs.SetParent(obj, lh)
	vs.SetParent(locus, lh)


image.thumb.png.13d2532fda6a3e23c7fff43057a75926.png




And next prototype Method can check if the center point of the section cache-geometry is inside the parent object on the design-layer.
 

lh = vs.ActLayer()
ln = vs.GetLName(lh)
espsilon = 1

c = "(INOBJECT & NOTINDLVP & NOTINREFDLVP & ((L='l-dummy') & (PON='XG Custom Part')))"
c = c.replace('l-dummy', ln)

custom_parts = []
def add_handle(h):
	custom_parts.append(h)


vs.ForEachObject(add_handle, c)



def is_pt3_in_cube(pt, cube, epsilon):
	x, y, z = pt
	xmin2, xmax2, ymin2, ymax2, zmin2, zmax2 = cube
	# vs.Message(str(cube))
	overlapx = overlapy = overlapz = False

	if xmin2 - epsilon < x < xmax2 + epsilon:
		overlapx = True

	if ymin2 - epsilon < y < ymax2 + epsilon:
		overlapy = True

	if zmin2 - epsilon < z < zmax2 + epsilon:
		overlapz = True

	return min(overlapx, overlapy, overlapz)


def bbox3D(p, zValue, height, width, depth):
	
	centerPt = (p[0], p[1], zValue)
	botZ = zValue - depth / 2
	topZ = zValue + depth / 2
	
	w2 = width / 2
	h2 = height / 2
	bbox_bl = p[0] - w2, p[1] - h2
	bbox_tr = p[0] + w2, p[1] + h2
	bbox_tl = p[0] - w2, p[1] + h2
	bbox_br = p[0] + w2, p[1] - h2

	xmin = bbox_tl[0]
	xmax = bbox_br[0]
	ymin = bbox_br[1]
	ymax = bbox_tl[1]
	zmin = botZ
	zmax = topZ

	return [xmin, xmax, ymin, ymax, zmin, zmax], ((xmin, ymin, zmin), (xmin, ymax, zmin), (xmax, ymax, zmin), (xmax, ymin, zmin), (xmin, ymin, zmax), (xmin, ymax, zmax), (xmax, ymax, zmax), (xmax, ymin, zmax))

#h = vs.FSActLayer()
h = custom_parts[0]

parent = vs.GetParent(vs.GetParent(h))

BOOLEAN, offset, rotationXAngle, rotationYAngle, rotationZAngle = vs.GetEntityMatrix(parent)

(p, zValue) = vs.Get3DCntr(h)
(height, width, depth) = vs.Get3DInfo(h)

cube, pts = bbox3D(p, zValue, height, width, depth)
is_in_cube = is_pt3_in_cube(pt, cube)

for pt in pts:
	x, y, z = pt
	x = x + offset[0]
	y = y + offset[1]
	z = z + offset[2]
	pt = x,y,z
	vs.Locus3D(pt)


Additional it would help to check classes and attributes to be sure not targeting an invisible object etc.
With this 3d Methods it is possible to manually make a relation between a coord point inside the section annotations and the object on the design-layer. 

The shakiness of this strategy here is, that the Method of traversing the VP to collect Section-Line and Section Geometry is maybe not reliable enough or can wreck after an VW Update.
Further it can be tricky to get positions of rotated and nested object rotations. That would be the the hardest part. Even the Data-Tag hat some (fixed) issues to find the Objects in every situation so I do expect that would be really expensive to solve that.

Also I saw, that I corrupted some VP after working on them with this scripts. But I think this was because of creating Test-Marker-Objects inside the VP. At the end, this would be a "read-only" access to the VP which should not corrupt anything -SHOULD.

I will pause working on that specific feature ☺️


 

Link to comment

I think you'll have better luck using the object variables rather than looking at the cache group:

// Viewport type selectors
// --------------
const short ovViewportProjectionType		= 1000;    	// short	read/write - the viewport projection type. - Public for VS
const short ovViewportRenderType			= 1001;		// short	read/write - the viewport render type. - Public for VS
const short ovViewportPerspectiveDistance	= 1002;		// real		read/write - the viewport perspective distance (used with custom perspective). - Public for VS
const short ovViewportScale					= 1003;		// real		read/write - the viewport scale. - Public for VS
const short ovViewportDirty					= 1004;		// Boolean  read/write - the viewport out-of-date (dirty) state. - Public for VS
const short ovViewportProject2D				= 1005;		// Boolean  read/write - the viewport project 2D state. - Public for VS
const short ovViewportRenderBackground		= 1006;		// Sint32		read/write - the viewport render background. - Public for VS
const short ovViewportViewType				= 1007;		// short	read/write - the viewport view type. - Public for VS
const short ovViewportLineWeightScale		= 1008;		// double	read/write - the viewport line weight scale. - Public for VS
const short ovViewportArrowheadScale		= 1009;		// double	read/write - the viewport arrowhead scale. - Public for VS
const short ovViewportDashedLineScale		= 1010;		// double	read/write - the viewport dashed line length/spacing scale. - Public for VS
const short ovViewportHatchLineScale		= 1011;		// double	read/write - the viewport hatch line spacing scale. - Public for VS
const short ovViewportDesignTextScale		= 1012;		// double	read/write - the viewport design layer referenced text size scale. - Public for VS
const short ovViewportSlashThicknessScale	= 1013;		// double	read/write - the viewport slash thcikness scale. - Public for VS
const short ovViewportAmbientIsOn			= 1014;		// Boolean  read/write - the viewport ambient light is ON or OFF. - Public for VS
const short ovViewportAmbientBrightness		= 1015;		// double	read/write - the viewport ambient light brightness. - Public for VS
const short ovViewportAmbientColor			= 1016;		// WorldPt3 read/write - the viewport ambient light color. - Public for VS
const short ovSetDesignLayerVisibilityInAllViewports	= 1017;	// short, -1 = invisible, 0 = normal, 2 = grayed - Public for VS
const short ovSetClassVisibilityInAllViewports			= 1018;	// short, -1 = invisible, 0 = normal, 2 = grayed - Public for VS
const short ovViewportHDRIBackground		= 1019;		// Sint32		read only  - the background for environment lighting - Public for VS
const short ovSectionVP2DAttributeClass		= 1020;		// Sint32		read only - the RefNumber of the class responsible for attributes of overall cross-section or just the x-section of structural elements. - Public for VS
const short ovSectionVP2DOtherAttribClass	= 1021;		// Sint32		read only - the RefNumber of the class responsible for attributes of cross-section generated from non-structural elements - Public for VS
const short ovSectionVP3DFillStyleClass		= 1022;		// Sint32     read only - the RefNumber of the class reposnsible for fill style of the objects beyond section plane - Public for VS
const short ovSectionVP3DLineStyleClass		= 1023;		// Sint32     read only - the RefNumber of the class responsible for line style of the objects beyond section plane - Public for VS
const short ovViewportXPosition				= 1024;		// double   read only - the X coordinate of the viewport on the sheet layer - Public for VS
const short ovViewportYPosition				= 1025;		// double   read only - the Y coordinate of the viewport on the sheet layer - Public for VS
const short ovViewportAngleWithXAxis		= 1026;		// double	read only - the angle that the viewport subtends with the X axis on the sheet layer in degrees - Public for VS
const short ovViewportShowWallComponents_OBSOLETE	= 1027;
const short ovViewportGrayTransparent		= 1028;		// Boolean  read/write - the viewport renders gray layers transparent - Public for VS
const short ovViewportFlipText				= 1029;		// Boolean  read/write - the viewport/dlvp adjusts for flipped text - Public for VS
const short ovViewportBlackAndWhite			= 1030;		// Boolean  read/write - the viewport/dlvp draws in black and white only - Public for VS
const short ovViewportUseDocumentClassVis	= 1031;		// Boolean  read/write - set/reads the Use Document Class visibilities settings for dlvps - Public for VS
const short ovViewportDescription			= 1032;		// TXString	read/write - a description for the viewport, which corresponds to the Dwg Title field for a corresponding Drawing Label. - Public for VS
const short ovViewportLocator				= 1033;		// TXString	read/write - the locator for the viewport, which corresponds to the Item field for a corresponding Drawing Label. - Public for VS
const short ovViewportIsLinked				= 1034;		// Boolean	read - indicates whether the viewport is a linked viewport
const short ovViewportDisplayPlanar			= 1035;		// Boolean	read/write - the flag to indicate if planar and 2D objects are to be displayed
const short ovViewportForegroundRenderType	= 1036;		// short	read/write - the viewport render type. - Public for VS
const short ovViewportHasCamera				= 1037;		// Boolean  read only  - whether there is a camera attached to the viewport or not
const short ovCameraAttachedToViewport		= 1038;		// Boolean  read only  - whether the camera is attached to a viewport or not
const short	ovViewportCropVisible			= 1039;		// Boolean  read/write - get/set the Crop Visible state of a viewport - Public for VS
const short	ovViewportLayerHeightIgnored	= 1040;		// Boolean  read only -  whether the viewport ignored layer height for single layer case
const short ovViewportLightingDevice		= 1041;		// read/write - make an association between a lighting device light and an overriden light object for the viewport.
const short ovViewportRePositionDimensionText	= 1042;	// Boolean  read/write - the viewport/dlvp re-positions dimension text to other side of dimension line - Public for VS
const short ovIsDesignLayerSectionViewport	= 1043;		// Boolean read only - indicates whether the linked viewport is a sheet layer or a design layer viewport - Public fo VS
const short ovFDLSVPHiddenLineInWireframe_OBSOLETE	= 1044;
const short ovViewportPageSymbolScale		= 1045;		// double	read/write - the viewport page symbol scale. - Public for VS
const short ovViewportNavigateToFromSectMarker = 1046;	// Boolean	write only - selects the viewport and makes it visible - Not for public use
const short ovViewportDetailLevel			= 1047;		// short read/write - low detail = 0, medium detail = 1, high detail = 2 - Public for VS
const short ovViewportIsHorizontalSection	= 1048;		// Boolean	read - indicates whether the viewport is horizontal section
const short ovViewportTransformMatrix		= 1049;		// TransformMatrix	read/write
const short ovViewportViewMatrix			= 1050;		// TransformMatrix	read/write
const short ovViewportOperatingTransform	= 1051;		// TransformMatrix	read
const short ovViewportUnscaledBoundsWithoutAnnotations	= 1052;		// WorldRect  read
const short ovViewportResetForOnlyAnnotationsChange = 1053; // void write
const short ovIsSectionViewport				= 1054;		// Boolean read only - indicates whether the viewport is a section viewport - Public for VS
const short ovSheetLayerSectionViewportViewMatrix	= 1055;		// TransformMatrix	read
const short ovSectionViewportSectionViewMatrix = 1056;		// TransformMatrix	read/write
const short ovViewportAttachDefaultRenderOptions = 1057;	// Boolean(ignored) write
const short ovViewportAttachDefaultCustomRenderWorksRenderOptions = 1058;	// Boolean(ignored) write
const short ovViewportDisplay2DComponents	= 1059;	// Boolean read/write
const short ovViewportHiddenLineDisplay2DFills		= 1060;	// Boolean read/write
const short ovViewportAttachDefaultLightingOptions	= 1061;	// void write
const short ovViewportCreateDefaultEditableGroups	= 1062;	// void write
const short ovViewportPrivateLayer					= 1063;	// MCObjectHandle read
const short ovSectionViewportDisplayObjectsBeyondCutPlane	= 1064;	// Boolean read/write
const short ovSectionViewportDisplayObjectsBeforeCutPlane	= 1065;	// Boolean read/write
const short ovViewportHiddenLineDisplay2DFillsAllowed		= 1066; // Boolean read
const short ovSectionViewportCastShadowsFromRemovedPortion	= 1077;	// Boolean read/write
const short ovSectionViewport2DResultsMerged				= 1078;	// Boolean read/write
const short ovSectionViewport2DAttributesUseClass			= 1079;	// Boolean read/write - must be set true before you set class with ovSectionViewport2DAttributesClass
const short ovSectionViewport2DAttributesClass				= 1080;	// RefNumber read/write
const short ovSectionViewport2DOtherAttribsUseClass			= 1081;	// Boolean read/write - must be set true before you set class with ovSectionViewport2DOtherAttribsClass
const short ovSectionViewport2DOtherAttribsClass			= 1082;	// RefNumber read/write

 

  • Like 2
Link to comment

@JBenghiat Please confirm:

Get/SetObjectVariableBoolean() will handles "Boolean" values

Get/SetObjectVariableInt() will set "handles "short"values

Get/SetObjectVariableLongInt() will handles "double" values

Get/SetObjectVariableReal() will handles "real" values

Get/SetObjectVariableString() will handles "TXString" values

 

What handles (gets/sets):

"Sint32"

"TransformMatrix"

"void" write

"RefNumber"

 

Are the constants labeled "Public for VS" the only ones accessible to vectorscript?

 

Yet again, TIA.

Link to comment

Double and real are synonymous. They both map to reals. 
 

Sint32 is a signed 32 bit integer. It maps to LONGINT. 
 

void is nothing, so there is no return. Using the standard SetOV call will probably work, ignoring the second argument. 

RefNumber is another LONGINT. It should work with Index2Name. 
 

I’m not sure what TransformationMatrix would return, if it works. In C, it’s an object that holds the transformation matrix as arrays. 
 

Calls marked “public for vs” just means that they duplicate a function elsewhere, but the only way you can access through VS is via an object variable. I think any call will work, it just may or may not return usable data. 

Edited by JBenghiat
  • Like 1
Link to comment

Hi Sam,

   You have the 1st five correct.

 

Short is an integer, so use Get/SetObjectVariableInt.

Sint32 is a Longint, so use Get/SetObjectVariableLongInt.

The "RefNumber" shown above are type Sint32 (Longint) - see previous line.

I'm guess on the "void write" entries, but judging from their ovNames, they may be BOOLEAN, but you can only write to then, and not read them. 

Not sure how to read or write a transform matrix from VS.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...