Class for processing selected objects

Print Previous page Top page Next page

Processing of selected objects includes executing a general sequence of commands for reading objects and indicating the execution of the processing operations, which are collected in the DoForEach service class in the doforeach.py script.

The use of a utility class when developing a script reduces the volume of the script by several times and reduces the number of programming errors.

An example of using the DoForEach class without passing an additional parameter:

 

def DeleteObjectHValue(_hmap:maptype.HMAP, _hobj:maptype.HOBJ, _parm = 0) -> int:

   if mapapi.mapIsObject3D(_hobj) == 0:

       return 0

   mapapi.mapSetObjectKind(_hobj, maptype.IDLONG2)

   mapapi.mapCommitObject(_hobj)

   return 1

 

def DeleteHValue(_hmap:maptype.HMAP, _hobj:maptype.HOBJ) -> float:

   if _hmap == 0:

       return 0

   dofunction = doforeach.DoForEach('Удаление высоты:', logapi.TAC_MED_HIGHT)

   result = dofunction.run(DeleteObjectHValue, _hmap, _hobj)

   return result

 

where:

 

DeleteObjectHValue – function that processes map objects

DeleteHValue – the main script function for processing selected objects

dofunction – an instance of the DoForEach class with parameters:

   'Удаление высоты:' – a comment in the progress bar,

   logapi.TAC_MED_HIGHT – transaction type identifier for this operation.

 

Example of using the DoForEach class with passing an additional parameter:

 

def MoveObject(_hmap:maptype.HMAP, _hobj:maptype.HOBJ,

                                 _parm:ctypes.POINTER(maptype.DOUBLEPOINT)) -> int:

   if _hobj == 0:

       return 0

   iret = mapapi.mapRelocateObjectPlane(_hobj, _parm)

   if iret != 0:

     return mapapi.mapCommitObject(_hobj)

   return 0

 

def MoveObjectsByDxDy(_hmap:maptype.HMAP, _hobj:maptype.HOBJ, dx, dy) -> int:

   if _hmap == 0:

       return 0

 

   dpoint = maptype.DOUBLEPOINT(dx, dy)

   dofunction = doforeach.DoForEach('Перемещение объектов:', logapi.TAC_MED_MOVE)

   result = dofunction.run(MoveObject, _hmap, _hobj, ctypes.byref(dpoint))

 

   mapapi.mapShowMessage(mapsyst.WTEXT('Обработано объектов - ' + str(result)),

                                                 mapsyst.WTEXT('Перемещение объектов'))

   mapapi.mapInvalidate()

   return result

 

The execution of processing is reduced to calling the run method, in which the name of the processing function, the map identifier and the identifier of the selected object from the main script function are passed.

The implementation of the run method has the following general form:

 

class DoForEach:

   ...

   def run(self, _function, hmap:maptype.HMAP, hobj:maptype.HOBJ, parm = 0):

       self.__readycount = 0

   ...

       if self.__actiontype != 0:

           logapi.mapLogCreateAction(hmap, hmap, self.__actiontype)

       ...

       hwork = mapapi.mapCreateObject(hmap)

       while (seekapi.mapTotalSeekObject(hmap, hwork, flag) != 0):

       ...

           if _function(hmap, hwork, parm) != 0:

               self.__readycount += 1

 

       if self.__actiontype != 0:

           logapi.mapLogCommitAction(hmap, hmap)

       if hwork != 0:

           mapapi.mapFreeObject(hwork)

       ...

       return self.__readycount