Jump to content

ConnectCAD Socket Heights - inspiration needed


Recommended Posts

Hello,

 

I've had a crack at this script over the last few days and can't find a way forward for it.

 

The goal here is to take a selection Circuits connected between Sockets on multiple Devices, and number them in the vertical order of the source end. The circuit connected to LAN 7 of Device 1 would be first, LAN 12 from Device 3 would be last. As this contrived example shows, it can't be based on the bounding box of the circuit because the 'other end' of a circuit may be higher than another, causing incorrect numbering.

 

 

image.png.9a640b6cefc5d4610b91e944ed18dc17.png

My approach so far:

- Build a list of the names of the source devices using the Src_Dev_Name field of the Circuits.

- For each device entry in the list, get it's handle (GetObject), then get it's Y height

- Iterate through sockets in it's profile group to get the position of the socket within the device

- Take device Y + socket Y to get the height of the socket in the drawing. 

 

Not yet written, but I would then build a list of:

DeviceName, SocketName, YHeight

sorted by Yheight, and iterate through all selected circuits, who would find their entry in the list (using their Src Dev and Src Skt fields) and get numbered accordingly.

 

So, I would appreciate some help on the below please:

- My current stumbling block is that GetObject of the device name doesn't find the handle of the device. Which I guess makes sense, as the Name of the PIO isn't necessarily the Name parameter within the Device. I'm not sure how to solve this.

- Is there an easier way than my method? I don't know whether I'm making it more complicated than it needs to be. Using things like ForEachObject and ForEachObjectInList makes it more challenging to pass arguments to functions and get lists back from them, so no idea how I'm going to do that yet.

 

(This is effectively building a duplicate of the ConnectCAD numbering tool, except that it will number the 'Cable' field, not the 'Number' field)

 

def buildsourcedevicelist():   # this function iterates through all selected circuits and stashes a list of unique device names
	target_cct = vs.FSActLayer()
	src_dev_names = set()
	while target_cct:
		check = vs.GetObjectVariableInt(target_cct, 1165)
		if check == 622:
			src_dev_name = vs.GetRField(target_cct, 'Circuit', 'Src_Dev_Name')
			if src_dev_name:
				src_dev_names.add(src_dev_name)
		target_cct = vs.NextSObj(target_cct)
	return list (src_dev_names)

srcdevnames = buildsourcedevicelist()
vs.AlrtDialog(f" + ".join(srcdevnames)) # sense check

def scanskts(h):
	if vs.GetObjectVariableInt(h, 1165) == 621:
		skt = vs.GetRField(h, 'Socket', 'Name')
		p = vs.GetSymLoc(h)
		x, y = p
		vs.AlrtDialog(f"Found A Socket = {skt} - {y}")

def scandevs(h):  # this function scans the list of source device names and gets their Y height
	vs.AlrtDialog(f"h is {h}")
	p = vs.GetSymLoc(h)
	x, y = p
	dev_name = vs.GetRField(h, 'Device', 'Name')
	vs.AlrtDialog(f"Device {dev_name} at {y}")
	devpg = vs.GetCustomObjectProfileGroup(h)
	vs.ForEachObjectInList(scanskts, 1, 0, vs.FInGroup(devpg))

for item in srcdevnames:
	devh = vs.GetObject(item)
	vs.AlrtDialog(devh)
	scandevs(devh)

 

 

 

Edited by spettitt
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...