Extracting block attribute values using Aspose.CAD for Java

I’m trying to extract the block attributes. I can open the drawing and get the block and attribute definitions :

CadImage cadImage = (CadImage) Image.load(dataDir + “A01.00-00-10.00.DWG”);

CadBlockEntity stempel = cadImage.getBlockEntities().get_Item(“StempelAUMC”);

for ( Enumerator<String, CadAttDef> it = stempel.getAttDefs().iterator(); it.hasNext(); ) {
KeyValuePair<String, CadAttDef> pair = it.next();

	System.err.println(pair.getKey() + ": " + pair.getValue().getDefaultString() );  

}

This is giving me the list of attribute definitions I need, but how can I get the actual attribute values of the block?

@bart.vanderschoot,

I have observed your comments. Can you please share source file so that we may further investigate to help you out.

I found a method to extract block attributes, first getting the definition and then looking for inserts:

@Override
public Map<String,String> findBlockAttributes(CadImage cadImage, String name) {
	 Map<String,String> attributes = new HashMap<>();
	 // get the block definition		
	 CadBlockEntity stempel =  cadImage.getBlockEntities().get_Item(name); 
	 // get the attribute definitions (should be in same order)
     Enumerator<String, CadAttDef> it = stempel.getAttDefs().iterator();
	
     for (CadBaseEntity entity : cadImage.getEntities())  {
    	 // look for inserted block instances  
    	 if (entity.getTypeName() == CadEntityTypeName.INSERT)  {
    		 // get the inserted block instance	
    		 CadInsertObject ins = (CadInsertObject) entity;
    		 // if this is the block we are looking for
    		 if (ins.getName().equals(name)) { 
    			 // loop through the child objects and select the attributes (should be in same order)
    			 for (CadBaseEntity childObject : entity.getChildObjects())   {
    				 if (childObject.getTypeName() == CadEntityTypeName.ATTRIB)   {	    					 
    					 if (it.hasNext()) { // should always
    						 KeyValuePair<String, CadAttDef> pair = it.next(); 	    		
    						 CadAttrib attribute = (CadAttrib) childObject;
	    					 attributes.put(pair.getKey(), attribute.getDefaultText()); 
    					 }	 
    				 }
    			 }
    		 }
    	 }
     } 

     return attributes;
}

@bart.vanderschoot,

I have observed your comments. Can you please confirm if you still need information or help.

Thanks your reply, but no further support needed.

@bart.vanderschoot,

Thank you for sharing your feedback.