Jump to content
Developer Wiki and Function Reference Links ×

Retrieving items from within PIO


Recommended Posts

I'm working on a plug-in that generates a lot of bitmaps from symbols.

To make it more user friendly i'm using the previously generated bitmaps in the PIO as a cache, I do this by setting kObjXPropPreserveContents to True and only delete out-of-date objects at redraw.

 

I tried using ForEachObjectInList starting at the PIO handle with deep traversal and start ignoring the callbacks once an object which does not have the PIO as parent.

The problem with this method is that once my object is not the front most object in the document the ignored callbacks start stacking up, the more backward the PIO placement is the more processing time the plug-in needs.

 

I'm now resorting to FInSymDef and NextObj, but NextObj never goes to None... so it feels like this is not the definitive method for what I need.

 

Is there any other way to loop over ONLY the items in the group of the PIO that is really scoped to the PIO?

And without having to check the parent of each of the looped objects 😉 [edit for more clarity]

 

With kind regards,

Jord Visser

Edited by Jord Visser
Link to comment

FIn3D() will give you the first object in the plug-in geometry. You can then use ForEachObjectInList() to iterate through all the objects in the group. You don't need to descend deep, as deleting any groups will also delete all the objects in the group.

 

That may be slightly more efficient than the routine I use, which is this:

 

		{//////// Clear Geometry ////////}
		Locus( 0, 0 );
		objHan := LNewObj;
		while ( objHan <> NIL ) & ( objHan <> FIn3D( PIHan ) ) do BEGIN
			nextHan := PrevObj( objHan );
			DelObject( objHan );
			objHan := nextHan;
		END;

I do know, however, this gets around any issues of needing to find the next object after an object that has just been removed.

Link to comment

@JBenghiat FIn3D did the job, looking back in the documentation 'Handle to first item in list' on the ForEachObjectInList() function should have given it away to me..

Thanks for the help!

 

As a little gift, my Python generator wrapper for ForEach* functions with a callback as the first argument:

The first argument is the VS function, followed by all of its parameters

class callback_iter:
	def __init__( self, func, *args ):
		self.objects = []
		self.sentinel = object( )
		
		def _callback( handle ):
			self.objects.append( handle )
			
		func( _callback, *args )
		self.objects.append( self.sentinel )
		
	def __iter__( self ):
		return self
	
	def __next__( self ):
		while True:
			if len(self.objects) > 0:
				obj = self.objects.pop(0)
				if obj is self.sentinel:
					raise StopIteration()
					break
				else:
					return obj
                                                         

for object_handle in callback_iter( vs.ForEachObjectInList, 0, 2, FirstHandleInList ):
  #do some magic

 

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...