Jump to content
Developer Wiki and Function Reference Links ×

Automate Data Tags in a Viewport


Fuge

Recommended Posts

Hey Guys... 

 

Here I am again looking for something that's probably not doable..  But I'm throwing it out there...   either I'm not seeing a way to do it,  or can't find the functions to data tag an object.

 

What I'm thinking....

 

1.   Select a viewport.

2.  Run the script.....

3.  All objects within the selected viewport, assigned to a particular class,  are automatically data tagged... 

 

*** when you have a bunch of viewports and everything in each needs a tag this would be a monster time saver ***

 

Any insight.. ideas... is appreciated...   

Thanks

Dave

  • Like 1
Link to comment

I'm working on a similar script at the moment, albeit in Python.

 

So far, I've gotten it near enough working in a design layer, and the next stage is to do it in VP Annotations. I'm not sure if VS:AddVPAnnotationObject would be enough, since it wouldn't know the handle of the specific object to be tagged.

 

I imagine you (we!) would need the handle of the viewport and then to traverse inside the Annotations Group using VS:GetVPGroup and find the handle of the object(s) in question.

 

To simply add a data tag, here's the small test function I've been using so far:

def tag(h):
    vs.AlrtDialog('Found Truss')
    newtag = vs.CreateCustomObjectN('Data Tag', 0,0, 0, False)
    vs.AlrtDialog('tag made')
    vs.SetPluginStyle(newtag, 'Truss Tag')
    vs.DT_AssociateWithObj(newtag, h)

 

So essentially - place the tag using CreateCustomObjectN, choose the style, then associate it with the object handle.

It generates all of them at the origin at the moment though, so I'll be working on setting the locations per tag soon.

 

  • Like 1
Link to comment

Okay...  I should of realized that Data Tag is a pio.     Knowing that here is the concept and example.  Hopefully useful to others...   I plan to tweak this further, but it shows it can be done.    See the attached file as well,  the procedure is on a script palette with a VP to look at..  

 

Thanks

Dave

 

Procedure Taggit;
VAR
 viewportHandle,VPGroupH, VPObject:HANDLE;
 VPName:STRING;
 ObjName:STRING;
  
PROCEDURE TagObj(H:HANDLE);
CONST
 TagName = 'Code Tag';
 LeaderAbove = 250mm;
 LeaderRight = 100mm;
 KVerticalOffset = 100mm;
VAR
 DataTagH,ObjectH,VPObject :HANDLE;
 StyleBoo, TagBoo,AnnoBoo :Boolean;
 TagX, TagY,x1,y1,x2,y2, pX, pY:REAL;
 ObjectTop, ObjectTopInSpace,  ObjectCenter, ObjectCenterInSpace, LeaderX, LeaderY :REAL;

BEGIN
   GetBBox(H,x1,y1,x2,y2);      
   ObjectTop:=y2;
   ObjectTopInSpace:= (y1);
     
   ObjectCenter:=  (x2-x1)/2;
   ObjectCenterInSpace:= ((x2-x1) + x1) - ((x2-x1)/2);
  
   DataTagH := CreateCustomObjectN('Data Tag', 0 ,0 ,0, False);
   StyleBoo := SetPluginStyle(DataTagH,TagName);
   TagBoo := DT_AssociateWithObj(DataTagH,H);
   AnnoBoo:= AddVPAnnotationObject( viewportHandle, DataTagH);	
 
   DataTagH:= Lnewobj;
   LeaderY:= ObjectTopInSpace+LeaderAbove;
   LeaderX:= ObjectCenterInSpace+LeaderRight;
	   
   HMove(DataTagH, LeaderX, LeaderY ); {Leader above center of object }

   SetRField(DataTagH,'Data Tag','__RefOffsetX',Num2StrF(Round(ObjectCenter))); { Move horizontal }
   SetRField(DataTagH,'Data Tag','__RefOffsetY',Num2StrF((ObjectTopInSpace-KVerticalOffset))); { Moves vertical }   
   SetRField(DataTagH,'Data Tag','Horizontal Position','Right'); { Default side the leader is placed }
   SetRField(DataTagH,'Data Tag','World-based','False');
   ResetObject(DataTagH);
  		
END;

BEGIN
  ViewportHandle := LSActLayer;
  If ViewportHandle=NIL THEN
  BEGIN
    AlrtDialog('Select a viewport!');
    Sysbeep;
    END ELSE
    BEGIN
      VPGroupH:= GetVPGroup( viewportHandle,2);
      VPObject := FInGroup(VPGroupH);
  
      { The record criteria, class, etc to tag }    
      ForEachObject(TagObj,((R IN ['Nimlok DB']) &(C='STEP-1') & (T<>LIGHT)));
  
      VPObject := NextObj(VPObject);
      UpdateVP( ViewportHandle);
      Redrawall;

  END;
END;

Run(Taggit);

 

AutoDataTag.vwx

  • Like 3
Link to comment
  • 1 month later...

Hey KingChaos,

 

See the attached...     The attached is saved back to VW22...    But not tested there... 

 

HTH ..  A lot more development is being worked on for this...  Something I'll post in the future.. 

 

Procedure Taggit;
VAR
 viewportHandle,VPGroupH, VPObject:HANDLE;
 VPName:STRING;
 ObjName:STRING;
  
PROCEDURE TagObj(H:HANDLE);
CONST
 TagName = 'Code Tag';
 LeaderAbove = 250mm;
 LeaderRight = 100mm;
 KVerticalOffset = 100mm;
VAR
 DataTagH,ObjectH,VPObject :HANDLE;
 StyleBoo, TagBoo,AnnoBoo :Boolean;
 TagX, TagY,x1,y1,x2,y2, pX, pY:REAL;
 ObjectTop, ObjectTopInSpace,  ObjectCenter, ObjectCenterInSpace, LeaderX, LeaderY :REAL;

BEGIN
   GetBBox(H,x1,y1,x2,y2);      
   ObjectTop:=y2;
   ObjectTopInSpace:= (y1);
     
   ObjectCenter:=  (x2-x1)/2;
   ObjectCenterInSpace:= ((x2-x1) + x1) - ((x2-x1)/2);
  
   DataTagH := CreateCustomObjectN('Data Tag', 0 ,0 ,0, False);
   StyleBoo := SetPluginStyle(DataTagH,TagName);
   TagBoo := DT_AssociateWithObj(DataTagH,H);
   AnnoBoo:= AddVPAnnotationObject( viewportHandle, DataTagH);    
 
   DataTagH:= Lnewobj;
   LeaderY:= ObjectTopInSpace+LeaderAbove;
   LeaderX:= ObjectCenterInSpace+LeaderRight;
       
   HMove(DataTagH, LeaderX, LeaderY ); {Leader above center of object }

   SetRField(DataTagH,'Data Tag','__RefOffsetX',Num2StrF(Round(ObjectCenter))); { Move horizontal }
   SetRField(DataTagH,'Data Tag','__RefOffsetY',Num2StrF((ObjectTopInSpace-KVerticalOffset))); { Moves vertical }   
   SetRField(DataTagH,'Data Tag','Horizontal Position','Right'); { Default side the leader is placed }
   SetRField(DataTagH,'Data Tag','World-based','False');
   ResetObject(DataTagH);
          
END;

BEGIN
  Layer('View-1');  { Example  Go to the layer you want by its name }
  ViewportHandle := GetObject('MyViewPort');  { Example - Get the Viewport you want be name, giving you a handle to it  }

  
  If ViewportHandle=NIL THEN
  BEGIN
    AlrtDialog('Select a viewport!');
    Sysbeep;
    END ELSE
    BEGIN
      VPGroupH:= GetVPGroup( viewportHandle,2);
      VPObject := FInGroup(VPGroupH);
  
      { The record criteria, class, etc to tag }    
      ForEachObject(TagObj,((R IN ['Nimlok DB']) &(C='STEP-1') & (T<>LIGHT)));
  
      VPObject := NextObj(VPObject);
      UpdateVP( ViewportHandle);
      Redrawall;

  END;
END;

Run(Taggit);

 

 

AutoDataTag_v2022.vwx

Link to comment
  • 1 month later...

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